diff --git a/.changeset/yellow-trains-protect.md b/.changeset/yellow-trains-protect.md index 62ff99f202..4b8c50ac3e 100644 --- a/.changeset/yellow-trains-protect.md +++ b/.changeset/yellow-trains-protect.md @@ -7,6 +7,7 @@ '@backstage/backend-tasks': patch '@backstage/plugin-app-backend': patch '@backstage/plugin-bazaar-backend': patch +'@backstage/plugin-scaffolder-backend': patch --- Changes needed to support MySQL diff --git a/plugins/app-backend/migrations/20211229105307_init.js b/plugins/app-backend/migrations/20211229105307_init.js index eb08f60e6a..dfc5f1229b 100644 --- a/plugins/app-backend/migrations/20211229105307_init.js +++ b/plugins/app-backend/migrations/20211229105307_init.js @@ -24,12 +24,12 @@ exports.up = async function up(knex) { table.comment( 'A cache of static assets that where previously deployed and may still be lazy-loaded by clients', ); - // setting to 64KB to account for long paths table - .string('path', 16383) + .uuid('id') .primary() .notNullable() - .comment('The path of the file'); + .comment('Auto-generated ID of the asset'); + table.text('path', 'text').notNullable().comment('The path of the file'); table .dateTime('last_modified_at') .defaultTo(knex.fn.now()) diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/DatabaseTaskStore.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/DatabaseTaskStore.ts index f3cb9b645e..c96bd6b9cd 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/DatabaseTaskStore.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/DatabaseTaskStore.ts @@ -261,18 +261,21 @@ export class DatabaseTaskStore implements TaskStore { tasks: { taskId: string }[]; }> { const { timeoutS } = options; - + let heartbeatInterval = this.db.raw(`? - interval '${timeoutS} seconds'`, [ + this.db.fn.now(), + ]); + if (this.db.client.config.client.includes('mysql')) { + heartbeatInterval = this.db.raw( + `date_sub(now(), interval ${timeoutS} second)`, + ); + } else if (this.db.client.config.client.includes('sqlite3')) { + heartbeatInterval = this.db.raw(`datetime('now', ?)`, [ + `-${timeoutS} seconds`, + ]); + } const rawRows = await this.db('tasks') .where('status', 'processing') - .andWhere( - 'last_heartbeat_at', - '<=', - this.db.client.config.client.includes('sqlite3') - ? this.db.raw(`datetime('now', ?)`, [`-${timeoutS} seconds`]) - : this.db.raw(`? - interval '${timeoutS} seconds'`, [ - this.db.fn.now(), - ]), - ); + .andWhere('last_heartbeat_at', '<=', heartbeatInterval); const tasks = rawRows.map(row => ({ taskId: row.id, }));