Merge pull request #21014 from backstage/rugvip/frequent-worker

backend-tasks: allow tasks to run more frequently than the default work check interval
This commit is contained in:
Patrik Oldsberg
2023-11-14 17:49:44 +01:00
committed by GitHub
2 changed files with 15 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.
+10 -1
View File
@@ -51,6 +51,15 @@ export class TaskWorker {
`Task worker starting: ${this.taskId}, ${JSON.stringify(settings)}`,
);
let workCheckFrequency = this.workCheckFrequency;
const isCron = !settings?.cadence.startsWith('P');
if (!isCron) {
const cadence = Duration.fromISO(settings.cadence);
if (cadence < workCheckFrequency) {
workCheckFrequency = cadence;
}
}
let attemptNum = 1;
(async () => {
for (;;) {
@@ -69,7 +78,7 @@ export class TaskWorker {
break;
}
await sleep(this.workCheckFrequency, options?.signal);
await sleep(workCheckFrequency, options?.signal);
}
this.logger.info(`Task worker finished: ${this.taskId}`);