Workflows
GuidesA job may wait for others. Spool.enqueue_after writes it Blocked, and it
runs, as any job does, once every job it waits for has completed:
let* rows = Spool.enqueue_many conn ~now import_row lines inlet* _ = Spool.enqueue_after conn ~now ~waits_for:rows summary file inThat is a batch with a summary, a workflow of one level; a job that waits for the summary makes it two. There is nothing else to learn: a workflow is its jobs and what each waits for.
When one fails
Section titled “When one fails”A job that fails – its attempts exhausted, discarded, expired or
cancelled – cancels every job that waits for it to complete, however far
down, each with a reason naming the job that failed and how. Each
cancelled one is failing in turn, so its own kind’s ~failed runs for it.
What waits on a job learns how it ended in the transaction that records
it, so no job is left blocked on one that has ended.
Whatever they came to
Section titled “Whatever they came to”A batch’s last step – telling the user the import finished, removing the
upload – must run whether every row completed or not. It waits with
~until:All_ended:
let* rows = Spool.enqueue_many conn ~now import_row lines inlet* _ = Spool.enqueue_after conn ~now ~waits_for:rows ~until:All_ended finish_import fileinIt runs once every job it waits for has ended, however: completed, or
failed and settled, so each failed one’s ~failed has committed first and
what the last step reads is final. A row’s failure never cancels it. Its
handler reads how each ended by Spool.workflow.
A job waited for is kept while anything waits for it: pruning passes it
over, delete refuses it, and a kind that keeps none keeps its row with
its payload emptied. So how it ended is always its own row’s state, and an
id the table does not hold – never given, or gone before the wait – is
refused with `Unknown_jobs, nothing written. Waiting for completion, one
already failed when the job is enqueued cancels it at once, and one ending as
it is enqueued is seen to, whichever commits first: the wait reads it under
a lock its ending waits for.
A retried job that waits for others waits again: retry what it waited for first.
No key
Section titled “No key”enqueue_after takes no unique key. A blocked job is outside the fold of
waiting jobs by key, and once released it would meet the job its key
already names.
Looking at one
Section titled “Looking at one”Spool.workflow conn id answers every job connected to one by waiting,
either way, with each one’s info, and the edges between them as (job, waits_for) pairs.
