backend-tasks: no unnecessary janitor log output on sqlite

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-02-22 11:27:53 +01:00
parent b734f71362
commit dc97845422
2 changed files with 13 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-tasks': patch
---
Only output janitor logs when actually timing out tasks
@@ -62,19 +62,21 @@ export class PluginTaskSchedulerJanitor {
const dbNull = this.knex.raw('null');
const tasksQuery = this.knex<DbTasksRow>(DB_TASKS_TABLE)
const tasks = await this.knex<DbTasksRow>(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}`);
}