backend-tasks: allow tasks to run more frequently than the default work check interval

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-11-06 16:45:46 -06:00
parent dc9ae6dacc
commit d8f488aaa8
2 changed files with 10 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-tasks': patch
---
Allow tasks to run more often that the default work check interval, which is 5 seconds.
@@ -51,6 +51,10 @@ export class TaskWorker {
`Task worker starting: ${this.taskId}, ${JSON.stringify(settings)}`,
);
const cadence = Duration.fromISO(settings.cadence);
const workCheckFrequency =
cadence < this.workCheckFrequency ? cadence : this.workCheckFrequency;
let attemptNum = 1;
(async () => {
for (;;) {
@@ -69,7 +73,7 @@ export class TaskWorker {
break;
}
await sleep(this.workCheckFrequency, options?.signal);
await sleep(workCheckFrequency, options?.signal);
}
this.logger.info(`Task worker finished: ${this.taskId}`);