Skip to main content

max / makenotwork

832 B · 16 lines History Blame Raw
1 -- Import-job liveness heartbeat, mirroring scan_jobs (migration 167).
2 --
3 -- An import runs on the bounded background pool, not a dedicated worker loop,
4 -- and had no liveness signal: a server crash mid-import stranded the job in
5 -- `processing` forever (the dashboard poller would show it running indefinitely
6 -- and the creator could never retry). `heartbeat_at` is stamped when the job
7 -- enters `processing` and bumped after every chunk; a scheduler reaper fails
8 -- jobs whose heartbeat has gone stale.
9 ALTER TABLE import_jobs ADD COLUMN heartbeat_at TIMESTAMPTZ;
10
11 -- Partial index for the reaper's `status = 'processing' AND heartbeat_at < …`
12 -- sweep — only in-flight jobs are ever scanned.
13 CREATE INDEX IF NOT EXISTS idx_import_jobs_processing_heartbeat
14 ON import_jobs (heartbeat_at)
15 WHERE status = 'processing';
16