Active Workflow Tracking and Cancellation
Track runtime instances in D1 so frontend/API can list and cancel in-flight work.
Table-driven State
Use workflow_runs as source of truth for control-plane operations.
States:
- active:
queued,running - terminal:
complete,failed,terminated
Creation + Transition
await createWorkflowRun(db, { workflowId, stage, videoId, triggerSource, status: 'queued' });
await markWorkflowRunRunning(db, workflowId);
On finish/failure:
markWorkflowRunComplete(...)markWorkflowRunFailed(...)
On manual cancellation:
- terminate workflow instance
markWorkflowRunTerminated(...)- update affected stage status on
videosrow tocancelledwhere applicable
API Pattern
GET /api/videos/workflows/activewith optional filters (videoId,stage).POST /api/videos/workflows/:workflowId/cancel.
Guardrail
Always read current run state before canceling to avoid canceling already terminal runs.