OXYGENHUB
◆ v0.9.7 oxygenhub / crates / hub / migrations-pg / 0091_work_queue.sql
880 B · SQL · last changed A durable work queue, first slice (refs #276) 15 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            BIGINT GENERATED BY DEFAULT AS IDENTITY 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     BIGINT NOT NULL,
11
    attempts      BIGINT NOT NULL DEFAULT 0,
12
    last_error    TEXT NOT NULL DEFAULT '',
13
    claimed_by    TEXT NOT NULL DEFAULT '',
14
    claimed_until BIGINT NOT NULL DEFAULT 0,
15
    dead          BOOLEAN NOT NULL DEFAULT FALSE,
16
    created_ms    BIGINT NOT NULL
17
);
18
CREATE INDEX work_queue_due ON work_queue (dead, run_after);