Merge pull request #18921 from PeteLevineA/continued-mysql-support

patch: Add Continued MySQL Support
This commit is contained in:
Fredrik Adelöw
2023-08-22 13:23:03 +02:00
committed by GitHub
28 changed files with 172 additions and 66 deletions
@@ -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<RawDbTaskRow>('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,
}));