0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 00:46:45 +01:00
posthog/rust/migrations/20231129172339_job_queue_table.sql
2024-06-10 14:00:00 +01:00

30 lines
971 B
SQL

CREATE TYPE job_status AS ENUM(
'available',
'completed',
'failed',
'running'
);
CREATE TABLE job_queue(
id BIGSERIAL PRIMARY KEY,
attempt INT NOT NULL DEFAULT 0,
attempted_at TIMESTAMPTZ DEFAULT NULL,
attempted_by TEXT [] DEFAULT ARRAY [] :: TEXT [],
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
errors JSONB [],
max_attempts INT NOT NULL DEFAULT 1,
metadata JSONB,
last_attempt_finished_at TIMESTAMPTZ DEFAULT NULL,
parameters JSONB,
queue TEXT NOT NULL DEFAULT 'default' :: text,
scheduled_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
status job_status NOT NULL DEFAULT 'available' :: job_status,
target TEXT NOT NULL
);
-- Needed for `dequeue` queries
CREATE INDEX idx_queue_scheduled_at ON job_queue(queue, status, scheduled_at, attempt);
-- Needed for UPDATE-ing incomplete jobs with a specific target (i.e. slow destinations)
CREATE INDEX idx_queue_target ON job_queue(queue, status, target);