Skip to content

Commit

Permalink
refactor: move version service scheduling to scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Oct 23, 2023
1 parent 53c4037 commit 0f5efed
Show file tree
Hide file tree
Showing 15 changed files with 7 additions and 24 deletions.
1 change: 0 additions & 1 deletion src/lib/routes/admin-api/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ async function getSetup() {
base,
request: supertest(app),
destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy();
},
};
Expand Down
1 change: 0 additions & 1 deletion src/lib/routes/admin-api/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ async function getSetup() {
base,
request: supertest(app),
destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy();
},
};
Expand Down
1 change: 0 additions & 1 deletion src/lib/routes/admin-api/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ async function getSetup() {
perms,
config,
destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy();
},
};
Expand Down
1 change: 0 additions & 1 deletion src/lib/routes/admin-api/public-signup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ describe('Public Signup API', () => {
stores,
perms,
destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy();
services.publicSignupTokenService.destroy();
},
Expand Down
1 change: 0 additions & 1 deletion src/lib/routes/admin-api/strategy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ async function getSetup() {
const app = await getApp(config, stores, services);

destroy = () => {
services.versionService.destroy();
services.clientInstanceService.destroy();
};

Expand Down
1 change: 0 additions & 1 deletion src/lib/routes/admin-api/tag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ async function getSetup() {
tagStore: stores.tagStore,
request: supertest(app),
destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy();
},
};
Expand Down
1 change: 0 additions & 1 deletion src/lib/routes/backstage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
1 change: 0 additions & 1 deletion src/lib/routes/client-api/feature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ async function getSetup() {
featureToggleClientStore: stores.featureToggleClientStore,
request: supertest(app),
destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy();
},
};
Expand Down
1 change: 0 additions & 1 deletion src/lib/routes/client-api/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ async function getSetup(opts?: IUnleashOptions) {
stores,
services,
destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy();
},
};
Expand Down
1 change: 0 additions & 1 deletion src/lib/routes/client-api/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ async function getSetup() {
request: supertest(app),
stores,
destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy();
},
};
Expand Down
1 change: 0 additions & 1 deletion src/lib/routes/health-check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ async function getSetup() {
request: supertest(app),
stores,
destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy();
},
};
Expand Down
1 change: 0 additions & 1 deletion src/lib/routes/public-invite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('Public Signup API', () => {
stores,
perms,
destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy();
services.publicSignupTokenService.destroy();
},
Expand Down
7 changes: 7 additions & 0 deletions src/lib/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const scheduleServices = async (
maintenanceService,
eventAnnouncerService,
featureToggleService,
versionService,
} = services;

if (await maintenanceService.isMaintenanceMode()) {
Expand Down Expand Up @@ -134,6 +135,12 @@ export const scheduleServices = async (
),
minutesToMilliseconds(1),
);

schedulerService.schedule(
versionService.checkLatestVersion.bind(versionService),
hoursToMilliseconds(48),
'checkLatestVersion',
);
};

export const createServices = (
Expand Down
11 changes: 0 additions & 11 deletions src/lib/services/version-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -169,11 +168,6 @@ export default class VersionService {
async setup(): Promise<void> {
await this.setInstanceId();
await this.checkLatestVersion();
this.timer = setInterval(
async () => this.checkLatestVersion(),
hoursToMilliseconds(48),
);
this.timer.unref();
}

async setInstanceId(): Promise<void> {
Expand Down Expand Up @@ -312,11 +306,6 @@ export default class VersionService {
instanceId: this.instanceId,
};
}

destroy(): void {
clearInterval(this.timer);
this.timer = null;
}
}

module.exports = VersionService;
1 change: 0 additions & 1 deletion src/test/e2e/helpers/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0f5efed

Please sign in to comment.