diff --git a/.changeset/tricky-phones-sing.md b/.changeset/tricky-phones-sing.md new file mode 100644 index 0000000000..df588fe585 --- /dev/null +++ b/.changeset/tricky-phones-sing.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-tasks': patch +--- + +Correctly set next run time for tasks diff --git a/packages/backend-tasks/src/tasks/TaskWorker.ts b/packages/backend-tasks/src/tasks/TaskWorker.ts index a60a0a4730..d2269d8118 100644 --- a/packages/backend-tasks/src/tasks/TaskWorker.ts +++ b/packages/backend-tasks/src/tasks/TaskWorker.ts @@ -283,8 +283,13 @@ export class TaskWorker { })}`, ); nextRun = this.knex.client.config.client.includes('sqlite3') - ? this.knex.raw('datetime(next_run_start_at, ?)', [`+${dt} seconds`]) - : this.knex.raw(`next_run_start_at + interval '${dt} seconds'`); + ? this.knex.raw( + `max(datetime(next_run_start_at, ?), datetime('now'))`, + [`+${dt} seconds`], + ) + : this.knex.raw( + `greatest(next_run_start_at + interval '${dt} seconds', now())`, + ); } const rows = await this.knex(DB_TASKS_TABLE)