fix: add conditional to database different postgres

Signed-off-by: Ana Luiza Ramalho dos Santos <analuiza@pop-os.localdomain>
This commit is contained in:
Ana Luiza Ramalho dos Santos
2023-01-02 18:08:34 -03:00
parent 9311ee4268
commit f0685193ef
2 changed files with 29 additions and 8 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-tasks': minor
---
Added the adapted query to mysql and sqlite3 databases to not returning warning on logs
@@ -53,15 +53,31 @@ export class PluginTaskSchedulerJanitor {
private async runOnce() {
const dbNull = this.knex.raw('null');
let tasks = [];
const configClient = this.knex.client.config.client;
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 (configClient.includes('sqlite3') || configClient.includes('mysql')) {
const now = await this.knex.select(this.knex.fn.now());
tasks = await this.knex<DbTasksRow>(DB_TASKS_TABLE)
.select('*')
.where('current_run_expires_at', '<', now);
await this.knex<DbTasksRow>(DB_TASKS_TABLE)
.where('current_run_expires_at', '<', now)
.update({
current_run_ticket: dbNull,
current_run_started_at: dbNull,
current_run_expires_at: dbNull,
});
} else {
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']);
}
// In rare cases, knex drivers may ignore "returning", and return the number
// of rows changed instead