Files
cobble/src/functions/backend/db/bots-queue/clear-finished-job-steps.ts
T
tbenandClaude Opus 5.5 a821013514 Clear finished jobs' steps a minute after they end
Job steps (bots_queue_updates) only feed the live working row, so the
new clear-job-steps cron deletes them shortly after a job ends, however
it ended, keeping their count on bots_queue.steps for the message
details. Not done the moment a job ends: the live relay would miss the
last ones.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 19:41:40 +01:00

22 lines
823 B
TypeScript

import BunSQLite from "@moduletrace/bun-sqlite";
import { AppData } from "@/src/data/app-data";
import clearFinishedJobStepsSql from "./clear-finished-job-steps-sql";
/**
* Clears the steps of jobs that ended more than `AppData.BotJobStepsKeepMs`
* ago, however they ended (completed, failed, cancelled, stopped, lost).
* Steps only feed the live working row; once the job's message is in they
* have no reader, and the job keeps their count. Not done the moment a job
* ends: steps reach the page only through the live relay, which would
* miss the last ones.
*/
export default async function clearFinishedJobSteps() {
const { count, clear } = clearFinishedJobStepsSql({
before: Date.now() - AppData.BotJobStepsKeepMs,
});
await BunSQLite.sql(count);
return await BunSQLite.sql(clear);
}