OXYGENHUB
◆ draft-ready oxygenhub / crates / hub / migrations / 0091_work_queue.sql
848 B · SQL · last changed A durable work queue, first slice (refs #276) 14 days ago source blame history raw
dd327d76 Andy McCall ↶ 1
-- A durable work queue (oxygenhub#276): work that must not be lost on a
2
-- restart or a failure, claimed by any worker process (SKIP LOCKED on
3
-- PostgreSQL), retried with backoff, kept as dead after its last attempt.
4
CREATE TABLE work_queue (
5
    id            INTEGER PRIMARY KEY,
6
    kind          TEXT NOT NULL,
7
    payload       TEXT NOT NULL DEFAULT '{}',
8
    -- One live item per kind and key: a second enqueue of the same is dropped.
9
    dedupe        TEXT NOT NULL DEFAULT '',
10
    run_after     INTEGER NOT NULL,
11
    attempts      INTEGER NOT NULL DEFAULT 0,
12
    last_error    TEXT NOT NULL DEFAULT '',
13
    claimed_by    TEXT NOT NULL DEFAULT '',
14
    claimed_until INTEGER NOT NULL DEFAULT 0,
15
    dead          INTEGER NOT NULL DEFAULT 0,
16
    created_ms    INTEGER NOT NULL
17
);
18
CREATE INDEX work_queue_due ON work_queue (dead, run_after);