2023-11-29 18:52:12 +01:00
|
|
|
CREATE TYPE job_status AS ENUM(
|
|
|
|
'available',
|
|
|
|
'completed',
|
|
|
|
'failed',
|
|
|
|
'running'
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE job_queue(
|
|
|
|
id BIGSERIAL PRIMARY KEY,
|
|
|
|
attempt INT NOT NULL DEFAULT 0,
|
2023-11-30 12:18:17 +01:00
|
|
|
attempted_at TIMESTAMPTZ DEFAULT NULL,
|
2024-01-05 16:29:24 +01:00
|
|
|
attempted_by TEXT [] DEFAULT ARRAY [] :: TEXT [],
|
2023-11-29 18:52:12 +01:00
|
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
2024-01-05 16:29:24 +01:00
|
|
|
errors JSONB [],
|
2023-12-01 12:47:20 +01:00
|
|
|
max_attempts INT NOT NULL DEFAULT 1,
|
2023-12-18 11:34:38 +01:00
|
|
|
metadata JSONB,
|
2024-01-05 16:29:24 +01:00
|
|
|
last_attempt_finished_at TIMESTAMPTZ DEFAULT NULL,
|
2023-12-01 12:47:20 +01:00
|
|
|
parameters JSONB,
|
2024-01-05 16:29:24 +01:00
|
|
|
queue TEXT NOT NULL DEFAULT 'default' :: text,
|
2023-12-01 12:47:20 +01:00
|
|
|
scheduled_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
2024-01-05 16:29:24 +01:00
|
|
|
status job_status NOT NULL DEFAULT 'available' :: job_status,
|
2023-12-01 12:47:20 +01:00
|
|
|
target TEXT NOT NULL
|
2023-11-29 18:52:12 +01:00
|
|
|
);
|
2023-12-12 19:44:21 +01:00
|
|
|
|
|
|
|
-- Needed for `dequeue` queries
|
2024-01-05 16:29:24 +01:00
|
|
|
CREATE INDEX idx_queue_scheduled_at ON job_queue(queue, status, scheduled_at, attempt);
|
2023-12-12 19:44:21 +01:00
|
|
|
|
|
|
|
-- Needed for UPDATE-ing incomplete jobs with a specific target (i.e. slow destinations)
|
2023-12-18 11:34:38 +01:00
|
|
|
CREATE INDEX idx_queue_target ON job_queue(queue, status, target);
|