mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
Remove timeout from store (#3018)
This commit is contained in:
parent
83aa4cc91b
commit
ab5da2116a
@ -5,7 +5,7 @@ import {
|
|||||||
IClientInstanceStore,
|
IClientInstanceStore,
|
||||||
INewClientInstance,
|
INewClientInstance,
|
||||||
} from '../types/stores/client-instance-store';
|
} from '../types/stores/client-instance-store';
|
||||||
import { hoursToMilliseconds, subDays } from 'date-fns';
|
import { subDays } from 'date-fns';
|
||||||
import Timeout = NodeJS.Timeout;
|
import Timeout = NodeJS.Timeout;
|
||||||
import { Db } from './db';
|
import { Db } from './db';
|
||||||
|
|
||||||
@ -62,12 +62,9 @@ export default class ClientInstanceStore implements IClientInstanceStore {
|
|||||||
store: 'instance',
|
store: 'instance',
|
||||||
action,
|
action,
|
||||||
});
|
});
|
||||||
const clearer = () => this._removeInstancesOlderThanTwoDays();
|
|
||||||
setTimeout(clearer, 10).unref();
|
|
||||||
this.timer = setInterval(clearer, hoursToMilliseconds(24)).unref();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async _removeInstancesOlderThanTwoDays(): Promise<void> {
|
async removeInstancesOlderThanTwoDays(): Promise<void> {
|
||||||
const rows = await this.db(TABLE)
|
const rows = await this.db(TABLE)
|
||||||
.whereRaw("created_at < now() - interval '2 days'")
|
.whereRaw("created_at < now() - interval '2 days'")
|
||||||
.del();
|
.del();
|
||||||
|
@ -253,6 +253,10 @@ export default class ClientInstanceService {
|
|||||||
return metrics;
|
return metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async removeInstancesOlderThanTwoDays(): Promise<void> {
|
||||||
|
return this.clientInstanceStore.removeInstancesOlderThanTwoDays();
|
||||||
|
}
|
||||||
|
|
||||||
destroy(): void {
|
destroy(): void {
|
||||||
this.timers.forEach(clearInterval);
|
this.timers.forEach(clearInterval);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ import { InstanceStatsService } from './instance-stats-service';
|
|||||||
import { FavoritesService } from './favorites-service';
|
import { FavoritesService } from './favorites-service';
|
||||||
import MaintenanceService from './maintenance-service';
|
import MaintenanceService from './maintenance-service';
|
||||||
import ExportImportService from './export-import-service';
|
import ExportImportService from './export-import-service';
|
||||||
import { minutesToMilliseconds } from 'date-fns';
|
import { hoursToMilliseconds, minutesToMilliseconds } from 'date-fns';
|
||||||
import { AccountService } from './account-service';
|
import { AccountService } from './account-service';
|
||||||
import { SchedulerService } from './scheduler-service';
|
import { SchedulerService } from './scheduler-service';
|
||||||
|
|
||||||
@ -52,6 +52,7 @@ export const scheduleServices = (
|
|||||||
schedulerService,
|
schedulerService,
|
||||||
apiTokenService,
|
apiTokenService,
|
||||||
instanceStatsService,
|
instanceStatsService,
|
||||||
|
clientInstanceService,
|
||||||
projectService,
|
projectService,
|
||||||
} = services;
|
} = services;
|
||||||
|
|
||||||
@ -70,11 +71,17 @@ export const scheduleServices = (
|
|||||||
minutesToMilliseconds(5),
|
minutesToMilliseconds(5),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
schedulerService.schedule(
|
||||||
|
clientInstanceService.removeInstancesOlderThanTwoDays.bind(
|
||||||
|
clientInstanceService,
|
||||||
|
),
|
||||||
|
hoursToMilliseconds(24),
|
||||||
|
);
|
||||||
|
|
||||||
if (config.flagResolver.isEnabled('projectStatusApi')) {
|
if (config.flagResolver.isEnabled('projectStatusApi')) {
|
||||||
const ONE_DAY = 1440;
|
|
||||||
schedulerService.schedule(
|
schedulerService.schedule(
|
||||||
projectService.statusJob.bind(projectService),
|
projectService.statusJob.bind(projectService),
|
||||||
minutesToMilliseconds(ONE_DAY),
|
hoursToMilliseconds(24),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -24,4 +24,5 @@ export interface IClientInstanceStore
|
|||||||
getDistinctApplications(): Promise<string[]>;
|
getDistinctApplications(): Promise<string[]>;
|
||||||
getDistinctApplicationsCount(daysBefore?: number): Promise<number>;
|
getDistinctApplicationsCount(daysBefore?: number): Promise<number>;
|
||||||
deleteForApplication(appName: string): Promise<void>;
|
deleteForApplication(appName: string): Promise<void>;
|
||||||
|
removeInstancesOlderThanTwoDays(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -82,4 +82,8 @@ export default class FakeClientInstanceStore implements IClientInstanceStore {
|
|||||||
async insert(details: INewClientInstance): Promise<void> {
|
async insert(details: INewClientInstance): Promise<void> {
|
||||||
this.instances.push({ createdAt: new Date(), ...details });
|
this.instances.push({ createdAt: new Date(), ...details });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeInstancesOlderThanTwoDays(): Promise<void> {
|
||||||
|
return Promise.resolve(undefined);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user