diff --git a/src/lib/routes/admin-api/config.test.ts b/src/lib/routes/admin-api/config.test.ts index b4aae85e1ad4..99a14438ccbc 100644 --- a/src/lib/routes/admin-api/config.test.ts +++ b/src/lib/routes/admin-api/config.test.ts @@ -29,7 +29,6 @@ async function getSetup() { base, request: supertest(app), destroy: () => { - services.versionService.destroy(); services.clientInstanceService.destroy(); }, }; diff --git a/src/lib/routes/admin-api/context.test.ts b/src/lib/routes/admin-api/context.test.ts index 95896b5864e7..c3b40594a083 100644 --- a/src/lib/routes/admin-api/context.test.ts +++ b/src/lib/routes/admin-api/context.test.ts @@ -21,7 +21,6 @@ async function getSetup() { base, request: supertest(app), destroy: () => { - services.versionService.destroy(); services.clientInstanceService.destroy(); }, }; diff --git a/src/lib/routes/admin-api/metrics.test.ts b/src/lib/routes/admin-api/metrics.test.ts index 640e1ff989a7..ef56d0876dfe 100644 --- a/src/lib/routes/admin-api/metrics.test.ts +++ b/src/lib/routes/admin-api/metrics.test.ts @@ -20,7 +20,6 @@ async function getSetup() { perms, config, destroy: () => { - services.versionService.destroy(); services.clientInstanceService.destroy(); }, }; diff --git a/src/lib/routes/admin-api/public-signup.test.ts b/src/lib/routes/admin-api/public-signup.test.ts index 84623301809f..8182755a0b91 100644 --- a/src/lib/routes/admin-api/public-signup.test.ts +++ b/src/lib/routes/admin-api/public-signup.test.ts @@ -34,7 +34,6 @@ describe('Public Signup API', () => { stores, perms, destroy: () => { - services.versionService.destroy(); services.clientInstanceService.destroy(); services.publicSignupTokenService.destroy(); }, diff --git a/src/lib/routes/admin-api/strategy.test.ts b/src/lib/routes/admin-api/strategy.test.ts index 55a83eb94af4..f8538ec62a73 100644 --- a/src/lib/routes/admin-api/strategy.test.ts +++ b/src/lib/routes/admin-api/strategy.test.ts @@ -19,7 +19,6 @@ async function getSetup() { const app = await getApp(config, stores, services); destroy = () => { - services.versionService.destroy(); services.clientInstanceService.destroy(); }; diff --git a/src/lib/routes/admin-api/tag.test.ts b/src/lib/routes/admin-api/tag.test.ts index 26944d7500ea..ad183a62ebc1 100644 --- a/src/lib/routes/admin-api/tag.test.ts +++ b/src/lib/routes/admin-api/tag.test.ts @@ -22,7 +22,6 @@ async function getSetup() { tagStore: stores.tagStore, request: supertest(app), destroy: () => { - services.versionService.destroy(); services.clientInstanceService.destroy(); }, }; diff --git a/src/lib/routes/backstage.test.ts b/src/lib/routes/backstage.test.ts index 93583eeec6c1..23572d566560 100644 --- a/src/lib/routes/backstage.test.ts +++ b/src/lib/routes/backstage.test.ts @@ -19,6 +19,5 @@ test('should enable prometheus', async () => { .get('/internal-backstage/prometheus') .expect('Content-Type', /text/) .expect(200); - services.versionService.destroy(); services.clientInstanceService.destroy(); }); diff --git a/src/lib/routes/client-api/feature.test.ts b/src/lib/routes/client-api/feature.test.ts index c4e5324d575a..727317aea11e 100644 --- a/src/lib/routes/client-api/feature.test.ts +++ b/src/lib/routes/client-api/feature.test.ts @@ -24,7 +24,6 @@ async function getSetup() { featureToggleClientStore: stores.featureToggleClientStore, request: supertest(app), destroy: () => { - services.versionService.destroy(); services.clientInstanceService.destroy(); }, }; diff --git a/src/lib/routes/client-api/metrics.test.ts b/src/lib/routes/client-api/metrics.test.ts index 9093fb201516..6da182e7878e 100644 --- a/src/lib/routes/client-api/metrics.test.ts +++ b/src/lib/routes/client-api/metrics.test.ts @@ -18,7 +18,6 @@ async function getSetup(opts?: IUnleashOptions) { stores, services, destroy: () => { - services.versionService.destroy(); services.clientInstanceService.destroy(); }, }; diff --git a/src/lib/routes/client-api/register.test.ts b/src/lib/routes/client-api/register.test.ts index 9a55816cc7be..64704e7513bc 100644 --- a/src/lib/routes/client-api/register.test.ts +++ b/src/lib/routes/client-api/register.test.ts @@ -15,7 +15,6 @@ async function getSetup() { request: supertest(app), stores, destroy: () => { - services.versionService.destroy(); services.clientInstanceService.destroy(); }, }; diff --git a/src/lib/routes/health-check.test.ts b/src/lib/routes/health-check.test.ts index c08bfeaab4d2..1149f8e8f6f3 100644 --- a/src/lib/routes/health-check.test.ts +++ b/src/lib/routes/health-check.test.ts @@ -16,7 +16,6 @@ async function getSetup() { request: supertest(app), stores, destroy: () => { - services.versionService.destroy(); services.clientInstanceService.destroy(); }, }; diff --git a/src/lib/routes/public-invite.test.ts b/src/lib/routes/public-invite.test.ts index e7015194e60b..3dbb1124497f 100644 --- a/src/lib/routes/public-invite.test.ts +++ b/src/lib/routes/public-invite.test.ts @@ -40,7 +40,6 @@ describe('Public Signup API', () => { stores, perms, destroy: () => { - services.versionService.destroy(); services.clientInstanceService.destroy(); services.publicSignupTokenService.destroy(); }, diff --git a/src/lib/services/index.ts b/src/lib/services/index.ts index 161e8339a7f2..7c361df34ade 100644 --- a/src/lib/services/index.ts +++ b/src/lib/services/index.ts @@ -76,6 +76,7 @@ export const scheduleServices = async ( maintenanceService, eventAnnouncerService, featureToggleService, + versionService, } = services; if (await maintenanceService.isMaintenanceMode()) { @@ -134,6 +135,12 @@ export const scheduleServices = async ( ), minutesToMilliseconds(1), ); + + schedulerService.schedule( + versionService.checkLatestVersion.bind(versionService), + hoursToMilliseconds(48), + 'checkLatestVersion', + ); }; export const createServices = ( diff --git a/src/lib/services/version-service.ts b/src/lib/services/version-service.ts index 3b9f6782c66b..a68b0aafd78c 100644 --- a/src/lib/services/version-service.ts +++ b/src/lib/services/version-service.ts @@ -16,7 +16,6 @@ import { IUnleashConfig } from '../types/option'; import version from '../util/version'; import { Logger } from '../logger'; import { ISettingStore } from '../types/stores/settings-store'; -import { hoursToMilliseconds } from 'date-fns'; import { IStrategyStore } from 'lib/types'; import { FEATURES_EXPORTED, FEATURES_IMPORTED } from '../types'; import { CUSTOM_ROOT_ROLE_TYPE } from '../util'; @@ -169,11 +168,6 @@ export default class VersionService { async setup(): Promise { await this.setInstanceId(); await this.checkLatestVersion(); - this.timer = setInterval( - async () => this.checkLatestVersion(), - hoursToMilliseconds(48), - ); - this.timer.unref(); } async setInstanceId(): Promise { @@ -312,11 +306,6 @@ export default class VersionService { instanceId: this.instanceId, }; } - - destroy(): void { - clearInterval(this.timer); - this.timer = null; - } } module.exports = VersionService; diff --git a/src/test/e2e/helpers/test-helper.ts b/src/test/e2e/helpers/test-helper.ts index 2941901bc855..0c98da663dde 100644 --- a/src/test/e2e/helpers/test-helper.ts +++ b/src/test/e2e/helpers/test-helper.ts @@ -199,7 +199,6 @@ async function createApp( const request = supertest.agent(app); const destroy = async () => { - services.versionService.destroy(); services.clientInstanceService.destroy(); services.clientMetricsServiceV2.destroy(); services.proxyService.destroy();