Files
Agent-System/deploy/postgres/goose/00020_2026-09-12-task-run-worker-lease.sql
T
weichenandCursor 3ade654256 feat(taskrun): add worker lease/heartbeat and Phase 5 fault injection tests
Introduce goose v20 lease columns with heartbeat loops so only expired
leases are marked interrupted on restart; add PG tests for concurrent
stage advance, active lease survival, and backup migration idempotency.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-13 02:50:23 +00:00

19 lines
865 B
SQL

-- +goose Up
-- Phase 4: 长任务 worker lease / heartbeat,用于识别孤儿 running 任务
ALTER TABLE task_runs ADD COLUMN IF NOT EXISTS worker_id TEXT NOT NULL DEFAULT '';
ALTER TABLE task_runs ADD COLUMN IF NOT EXISTS lease_expires_at TIMESTAMPTZ;
ALTER TABLE task_runs ADD COLUMN IF NOT EXISTS lease_heartbeat_at TIMESTAMPTZ;
ALTER TABLE task_runs ADD COLUMN IF NOT EXISTS attempt INT NOT NULL DEFAULT 1;
CREATE INDEX IF NOT EXISTS idx_task_runs_stale_lease
ON task_runs(lease_expires_at)
WHERE status = 'running' AND lease_expires_at IS NOT NULL;
-- +goose Down
DROP INDEX IF EXISTS idx_task_runs_stale_lease;
ALTER TABLE task_runs DROP COLUMN IF EXISTS attempt;
ALTER TABLE task_runs DROP COLUMN IF EXISTS lease_heartbeat_at;
ALTER TABLE task_runs DROP COLUMN IF EXISTS lease_expires_at;
ALTER TABLE task_runs DROP COLUMN IF EXISTS worker_id;