1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00

refactor: move version service scheduling to scheduler (#5120)

This commit is contained in:
Mateusz Kwasniewski 2023-10-23 11:34:03 +02:00 committed by GitHub
parent 8c97847797
commit 828e463e38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 7 additions and 24 deletions

View File

@ -25,7 +25,6 @@ async function getSetup() {
clientFeatureToggleStore: stores.clientFeatureToggleStore, clientFeatureToggleStore: stores.clientFeatureToggleStore,
request: supertest(app), request: supertest(app),
destroy: () => { destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy(); services.clientInstanceService.destroy();
}, },
}; };

View File

@ -29,7 +29,6 @@ async function getSetup() {
base, base,
request: supertest(app), request: supertest(app),
destroy: () => { destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy(); services.clientInstanceService.destroy();
}, },
}; };

View File

@ -21,7 +21,6 @@ async function getSetup() {
base, base,
request: supertest(app), request: supertest(app),
destroy: () => { destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy(); services.clientInstanceService.destroy();
}, },
}; };

View File

@ -20,7 +20,6 @@ async function getSetup() {
perms, perms,
config, config,
destroy: () => { destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy(); services.clientInstanceService.destroy();
}, },
}; };

View File

@ -34,7 +34,6 @@ describe('Public Signup API', () => {
stores, stores,
perms, perms,
destroy: () => { destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy(); services.clientInstanceService.destroy();
services.publicSignupTokenService.destroy(); services.publicSignupTokenService.destroy();
}, },

View File

@ -19,7 +19,6 @@ async function getSetup() {
const app = await getApp(config, stores, services); const app = await getApp(config, stores, services);
destroy = () => { destroy = () => {
services.versionService.destroy();
services.clientInstanceService.destroy(); services.clientInstanceService.destroy();
}; };

View File

@ -22,7 +22,6 @@ async function getSetup() {
tagStore: stores.tagStore, tagStore: stores.tagStore,
request: supertest(app), request: supertest(app),
destroy: () => { destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy(); services.clientInstanceService.destroy();
}, },
}; };

View File

@ -19,6 +19,5 @@ test('should enable prometheus', async () => {
.get('/internal-backstage/prometheus') .get('/internal-backstage/prometheus')
.expect('Content-Type', /text/) .expect('Content-Type', /text/)
.expect(200); .expect(200);
services.versionService.destroy();
services.clientInstanceService.destroy(); services.clientInstanceService.destroy();
}); });

View File

@ -1,5 +1,4 @@
import supertest from 'supertest'; import supertest from 'supertest';
import createStores from '../../../test/fixtures/store';
import getApp from '../../app'; import getApp from '../../app';
import { createTestConfig } from '../../../test/config/test-config'; import { createTestConfig } from '../../../test/config/test-config';
import { clientMetricsSchema } from '../../services/client-metrics/schema'; import { clientMetricsSchema } from '../../services/client-metrics/schema';
@ -21,7 +20,6 @@ async function getSetup(opts?: IUnleashOptions) {
stores: db.stores, stores: db.stores,
services, services,
destroy: async () => { destroy: async () => {
services.versionService.destroy();
services.clientInstanceService.destroy(); services.clientInstanceService.destroy();
await db.destroy(); await db.destroy();
}, },

View File

@ -15,7 +15,6 @@ async function getSetup() {
request: supertest(app), request: supertest(app),
stores, stores,
destroy: () => { destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy(); services.clientInstanceService.destroy();
}, },
}; };

View File

@ -16,7 +16,6 @@ async function getSetup() {
request: supertest(app), request: supertest(app),
stores, stores,
destroy: () => { destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy(); services.clientInstanceService.destroy();
}, },
}; };

View File

@ -40,7 +40,6 @@ describe('Public Signup API', () => {
stores, stores,
perms, perms,
destroy: () => { destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy(); services.clientInstanceService.destroy();
services.publicSignupTokenService.destroy(); services.publicSignupTokenService.destroy();
}, },

View File

@ -116,6 +116,7 @@ export const scheduleServices = async (
maintenanceService, maintenanceService,
eventAnnouncerService, eventAnnouncerService,
featureToggleService, featureToggleService,
versionService,
lastSeenService, lastSeenService,
} = services; } = services;
@ -198,6 +199,12 @@ export const scheduleServices = async (
minutesToMilliseconds(1), minutesToMilliseconds(1),
'updatePotentiallyStaleFeatures', 'updatePotentiallyStaleFeatures',
); );
schedulerService.schedule(
versionService.checkLatestVersion.bind(versionService),
hoursToMilliseconds(48),
'checkLatestVersion',
);
}; };
export const createServices = ( export const createServices = (

View File

@ -16,7 +16,6 @@ import { IUnleashConfig } from '../types/option';
import version from '../util/version'; import version from '../util/version';
import { Logger } from '../logger'; import { Logger } from '../logger';
import { ISettingStore } from '../types/stores/settings-store'; import { ISettingStore } from '../types/stores/settings-store';
import { hoursToMilliseconds } from 'date-fns';
import { IStrategyStore } from 'lib/types'; import { IStrategyStore } from 'lib/types';
import { FEATURES_EXPORTED, FEATURES_IMPORTED } from '../types'; import { FEATURES_EXPORTED, FEATURES_IMPORTED } from '../types';
import { CUSTOM_ROOT_ROLE_TYPE } from '../util'; import { CUSTOM_ROOT_ROLE_TYPE } from '../util';
@ -191,11 +190,6 @@ export default class VersionService {
async setup(): Promise<void> { async setup(): Promise<void> {
await this.setInstanceId(); await this.setInstanceId();
await this.checkLatestVersion(); await this.checkLatestVersion();
this.timer = setInterval(
async () => this.checkLatestVersion(),
hoursToMilliseconds(48),
);
this.timer.unref();
} }
async setInstanceId(): Promise<void> { async setInstanceId(): Promise<void> {
@ -365,11 +359,6 @@ export default class VersionService {
instanceId: this.instanceId, instanceId: this.instanceId,
}; };
} }
destroy(): void {
clearInterval(this.timer);
this.timer = null;
}
} }
module.exports = VersionService; module.exports = VersionService;