Skip to content

Commit

Permalink
More sensible defaults for PeriodicTask.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkaemming committed Dec 6, 2023
1 parent 6c4b2d9 commit f239cd9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion plugin-server/src/main/pluginsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion plugin-server/src/utils/periodic-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class PeriodicTask {
private running = true
private abortController: AbortController

constructor(task: () => Promise<void> | void, intervalMs = 1000, minimumWaitMs = 1000) {
constructor(task: () => Promise<void> | void, intervalMs: number, minimumWaitMs = 0) {
this.abortController = new AbortController()

const abortRequested = new Promise((resolve) => {
Expand Down
4 changes: 2 additions & 2 deletions plugin-server/src/worker/ingestion/person-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions plugin-server/tests/utils/periodic-task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit f239cd9

Please sign in to comment.