diff --git a/.changeset/nervous-pears-cover.md b/.changeset/nervous-pears-cover.md new file mode 100644 index 0000000000..165fea96c0 --- /dev/null +++ b/.changeset/nervous-pears-cover.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-tasks': patch +--- + +Only output janitor logs when actually timing out tasks diff --git a/packages/backend-tasks/src/tasks/PluginTaskSchedulerJanitor.ts b/packages/backend-tasks/src/tasks/PluginTaskSchedulerJanitor.ts index 8b90afff42..c77fe4e925 100644 --- a/packages/backend-tasks/src/tasks/PluginTaskSchedulerJanitor.ts +++ b/packages/backend-tasks/src/tasks/PluginTaskSchedulerJanitor.ts @@ -62,19 +62,21 @@ export class PluginTaskSchedulerJanitor { const dbNull = this.knex.raw('null'); - const tasksQuery = this.knex(DB_TASKS_TABLE) + const tasks = await this.knex(DB_TASKS_TABLE) .where('current_run_expires_at', '<', this.knex.fn.now()) .update({ current_run_ticket: dbNull, current_run_started_at: dbNull, current_run_expires_at: dbNull, - }); + }) + .returning(['id']); - if (this.knex.client.config.client === 'sqlite3') { - const tasks = await tasksQuery; - this.logger.warn(`${tasks} tasks timed out and were lost`); + // sqlite ignores "returning", returns number of rows changed instead + if (typeof tasks === 'number') { + if (tasks > 0) { + this.logger.warn(`${tasks} tasks timed out and were lost`); + } } else { - const tasks = await tasksQuery.returning(['id']); for (const { id } of tasks) { this.logger.warn(`Task timed out and was lost: ${id}`); }