0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-25 11:17:50 +01:00
posthog/migrations/20231129172339_job_queue_table.sql

28 lines
918 B
MySQL
Raw Normal View History

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,
attempted_by TEXT[] DEFAULT ARRAY[]::TEXT[],
2023-11-29 18:52:12 +01:00
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
2023-12-01 12:47:20 +01:00
errors jsonb[],
max_attempts INT NOT NULL DEFAULT 1,
2023-11-29 18:52:12 +01:00
finished_at TIMESTAMPTZ DEFAULT NULL,
2023-12-01 12:47:20 +01:00
parameters JSONB,
queue TEXT NOT NULL DEFAULT 'default'::text,
scheduled_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
2023-11-29 18:52:12 +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
CREATE INDEX idx_queue_scheduled_at ON job_queue(queue, status, scheduled_at);
-- 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);