diff --git a/plugin-server/src/main/pluginsServer.ts b/plugin-server/src/main/pluginsServer.ts index 9e132db6d9d74..f59d196e93d24 100644 --- a/plugin-server/src/main/pluginsServer.ts +++ b/plugin-server/src/main/pluginsServer.ts @@ -437,7 +437,7 @@ export async function startPluginsServer( const postgres = hub?.postgres ?? new PostgresRouter(serverConfig) const kafkaProducer = hub?.kafkaProducer ?? (await createKafkaProducerWrapper(serverConfig)) - personOverridesPeriodicTask = new DeferredPersonOverrideWorker(postgres, kafkaProducer).runTask() + personOverridesPeriodicTask = new DeferredPersonOverrideWorker(postgres, kafkaProducer).runTask(5000) personOverridesPeriodicTask.promise.catch(async () => { status.error('⚠️', 'Person override worker task crashed! Requesting shutdown...') await closeJobs() diff --git a/plugin-server/src/utils/periodic-task.ts b/plugin-server/src/utils/periodic-task.ts index c6cfed96dea68..e0c0bfddae385 100644 --- a/plugin-server/src/utils/periodic-task.ts +++ b/plugin-server/src/utils/periodic-task.ts @@ -6,7 +6,7 @@ export class PeriodicTask { private running = true private abortController: AbortController - constructor(task: () => Promise | void, intervalMs = 1000, minimumWaitMs = 1000) { + constructor(task: () => Promise | void, intervalMs: number, minimumWaitMs = 0) { this.abortController = new AbortController() const abortRequested = new Promise((resolve) => { diff --git a/plugin-server/src/worker/ingestion/person-state.ts b/plugin-server/src/worker/ingestion/person-state.ts index c9b5b767d0bdf..08a659d16d8c3 100644 --- a/plugin-server/src/worker/ingestion/person-state.ts +++ b/plugin-server/src/worker/ingestion/person-state.ts @@ -808,12 +808,12 @@ export class DeferredPersonOverrideWorker { }) } - public runTask(): PeriodicTask { + public runTask(intervalMs: number): PeriodicTask { return new PeriodicTask(async () => { status.debug('👥', 'Processing pending overrides...') const overridesCount = await this.processPendingOverrides() ;(overridesCount > 0 ? status.info : status.debug)('👥', `Processed ${overridesCount} pending overrides.`) - }) + }, intervalMs) } } diff --git a/plugin-server/tests/utils/periodic-task.test.ts b/plugin-server/tests/utils/periodic-task.test.ts index 805517485adac..da570281e1b45 100644 --- a/plugin-server/tests/utils/periodic-task.test.ts +++ b/plugin-server/tests/utils/periodic-task.test.ts @@ -4,7 +4,7 @@ describe('PeriodicTask', () => { describe('updates completion status', () => { it('on success', async () => { const fn = jest.fn() - const task = new PeriodicTask(fn) + const task = new PeriodicTask(fn, 1000) expect(fn).toBeCalled() expect(task.isRunning()).toEqual(true) await task.stop() @@ -15,7 +15,7 @@ describe('PeriodicTask', () => { const fn = jest.fn(() => { throw new Error() }) - const task = new PeriodicTask(fn) + const task = new PeriodicTask(fn, 1000) expect(fn).toBeCalled() await task.stop() expect(task.isRunning()).toEqual(false)