Run transcode jobs on several workers at once

Database · PostgreSQL · advanced · modification

Transcoding is the slowest step after an upload, and one worker thread can no longer keep up at peak. This PR lets the worker scale out: `main()` starts `WORKER_CONCURRENCY` threads (default 4) through the existing `run_threads` supervisor, and the deployment change to 3 worker pods ships with it (infra repo). Since several workers now read the same queue, the query that picks the next job claims it: `FOR UPDATE SKIP LOCKED` locks the oldest queued row and lets the other workers skip past it to the next one, so jobs are spread across workers. Everything else in `run_once` (marking a job `done` or `failed`) is unchanged. Adds worker tests in `tests/test_transcode_worker.py`.

Video platform worker, Python 3.12 with psycopg 3.2 (plain SQL, no ORM) against one PostgreSQL 16 primary at the default isolation level, READ COMMITTED. `app.db.worker_connection()` (existing) returns a dedicated `psycopg.connect(DATABASE_URL, autocommit=True)` connection; every worker in this codebase uses autocommit connections. `app.supervisor.run_threads(target, count, stop)` (existing) runs `target(stop)` in `count` threads and starts a call again after logging it when it raises. `app.transcoder.transcode(video_id, preset)` (existing) takes from about 10 seconds to at most 3 minutes, writes the output to object storage under a key derived from `video_id` and `preset` (overwriting), and raises `transcoder.TranscodeError` for every failure of the job itself (unreadable input, unsupported codec, upload rejected); any other exception means the worker itself broke. Table `transcode_jobs` (earlier migration): `id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY`, `video_id bigint NOT NULL`, `preset text NOT NULL`, `status text NOT NULL DEFAULT 'queued'` with `CHECK (status IN ('queued', 'done', 'failed'))`, `error text` nullable, `created_at timestamptz NOT NULL DEFAULT now()`, `finished_at timestamptz` nullable, and a partial index on `(created_at, id) WHERE status = 'queued'`. The upload API inserts a queued job per (video, preset); nothing else changes a job's row. `WORKER_CONCURRENCY` is set by the worker deployment manifest to 4 on every pod; the supported range is 1 to 4. The worker database role has `idle_in_transaction_session_timeout = '5min'`, longer than any job, and the team accepts one open transaction per busy worker thread (at most 12). The test suite (`tests/conftest.py`, existing) builds a fresh test database from the migrations, empties `transcode_jobs` before each test, and provides `enqueue_job(video_id, preset="720p")` (returns the job id) and `fetch_one(sql, params)`.

Requirements

Files touched

Review this PR

Database practice