The tasks table
CREATE TABLE adk_tasks (
id uuid PRIMARY KEY,
session_id uuid NOT NULL REFERENCES adk_sessions(id) ON DELETE CASCADE,
status text NOT NULL, -- pending, running, waiting, completed, failed
waiting_for text, -- human, timer, webhook
wake_at timestamptz,
state jsonb NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);Advertisement
The wake-up query
SELECT id FROM adk_tasks
WHERE status = 'waiting' AND wake_at <= now()
ORDER BY wake_at LIMIT 100
FOR UPDATE SKIP LOCKED;Advertisement
SKIP LOCKED for workers
Multiple worker processes can poll the same table without stepping on each other. SKIP LOCKED gives each worker a distinct slice of ready tasks.