Class: Wurk::Flow::Completion
- Inherits:
-
Object
- Object
- Wurk::Flow::Completion
- Defined in:
- lib/wurk/flow/completion.rb
Overview
What a node finishing means for the rest of the graph.
Registered as the :success and :death callback of every node's batch
at creation, so it arrives the way any batch callback does: as an ordinary
Batch::CallbackJob on the flow's callback queue, retried like any
other job. Nothing polls, and nothing here counts a node's jobs — the
batch already knows when its own job is done, and this only answers what
the graph does next. That division is the whole design: a second
completion tracker is a second thing that can disagree with the first.
Both answers are one Lua call, because both are races. on_success is the
sibling race — two dependencies of the same node finishing at once, where
reading "how many are left" and then deciding runs the parent twice or
never. on_death races the retry that saves it. Neither can be resolved
by this process, and neither tries: the scripts claim, and a callback that
runs twice writes once.
Instance Method Summary collapse
-
#on_death(_status, options) ⇒ Object
A node's job died.
-
#on_success(_status, options) ⇒ Object
A node succeeded.
Instance Method Details
#on_death(_status, options) ⇒ Object
A node's job died. Its dependents are not cancelled — they are simply
never released, because a batch holding a dead job never fires
:success — so all this does is make that visible on the flow record.
The claim decides whether this is news: a callback job redelivered
against an already-dead node has nothing to report.
49 50 51 52 53 54 |
# File 'lib/wurk/flow/completion.rb', line 49 def on_death(_status, ) fid, index = address() return unless mark_dead(fid, index).to_i == 1 Wurk.logger.warn("flow #{fid}: node #{index} died; nothing downstream of it will run") end |
#on_success(_status, options) ⇒ Object
A node succeeded. Release whatever was waiting only on it, and settle the flow if it was the last node.
The batch Batch::Status the callback contract hands over says nothing this needs: the node's address travels in the callback options, written when the graph was created, and every fact about the graph is read inside the script that acts on it. What comes back is the flow's remaining node count — dropped, because the record already carries it — then what the call released, then what it refused to.
37 38 39 40 41 42 |
# File 'lib/wurk/flow/completion.rb', line 37 def on_success(_status, ) fid, index = address() _pending, released, broken = Array(advance(fid, index)) emit_enqueued(Array(released)) report_broken(fid, Array(broken)) end |