Track running Granthi review queue jobs
This commit is contained in:
@@ -35,6 +35,7 @@ const DDL = [
|
||||
state TEXT NOT NULL DEFAULT 'queued',
|
||||
outcome TEXT,
|
||||
created_ts TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
|
||||
started_ts TEXT,
|
||||
finished_ts TEXT
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_queue_jobs_state ON queue_jobs(state)`
|
||||
@@ -44,9 +45,17 @@ export function openDb(dbPath) {
|
||||
mkdirSync(dirname(dbPath), { recursive: true });
|
||||
const db = new DatabaseSync(dbPath);
|
||||
for (const stmt of DDL) db.prepare(stmt).run();
|
||||
ensureColumn(db, 'queue_jobs', 'started_ts', 'TEXT');
|
||||
return db;
|
||||
}
|
||||
|
||||
function ensureColumn(db, table, column, type) {
|
||||
const columns = db.prepare(`PRAGMA table_info(${table})`).all();
|
||||
if (!columns.some((c) => c.name === column)) {
|
||||
db.prepare(`ALTER TABLE ${table} ADD COLUMN ${column} ${type}`).run();
|
||||
}
|
||||
}
|
||||
|
||||
export function insertReview(db, r) {
|
||||
const stmt = db.prepare(`
|
||||
INSERT INTO reviews (repo, sha, pr, event, pusher, authors, trailers, axes,
|
||||
@@ -76,6 +85,13 @@ export function enqueueJob(db, job) {
|
||||
return res.lastInsertRowid;
|
||||
}
|
||||
|
||||
export function startJob(db, id) {
|
||||
db.prepare(
|
||||
`UPDATE queue_jobs SET state = 'running',
|
||||
started_ts = strftime('%Y-%m-%dT%H:%M:%fZ','now') WHERE id = ?`
|
||||
).run(id);
|
||||
}
|
||||
|
||||
export function finishJob(db, id, outcome = null) {
|
||||
db.prepare(
|
||||
`UPDATE queue_jobs SET state = 'done', outcome = ?,
|
||||
|
||||
Reference in New Issue
Block a user