From ebbec677e1ac628d4f3d68d81d56fc5fb1da74a5 Mon Sep 17 00:00:00 2001 From: Phil Kuang Date: Thu, 28 Apr 2022 13:46:42 -0400 Subject: [PATCH] fix(tasks): set next run time relative to now Signed-off-by: Phil Kuang --- .changeset/tricky-phones-sing.md | 5 +++++ packages/backend-tasks/src/tasks/TaskWorker.ts | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changeset/tricky-phones-sing.md 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)