Class: Wurk::Flow::Chain

Inherits:
Object
  • Object
show all
Defined in:
lib/wurk/flow/chain.rb

Overview

A flow with one path through it, where every step is handed the step before it.

Wurk::Flow.chain do |c|
c.job(FetchJob, 'https://example.com')
c.job(ParseJob)                          # gets FetchJob's result
c.job(StoreJob, 'reports')               # gets ParseJob's result
end.run

No new machinery: this is Builder's pipe: applied to the node before, once per step. Everything a flow does — atomic creation, the caps, failure propagation, abandon — applies unchanged, and a chain is inspectable as the graph it is rather than as a second kind of object.

The argument arrives last, after whatever the step declared for itself: c.job(StoreJob, 'reports') runs StoreJob#perform('reports', result). Prepending it would mean a step's own arguments change position depending on where in the chain it sits.

Instance Method Summary collapse

Constructor Details

#initialize(builder) ⇒ Chain

Returns a new instance of Chain.



24
25
26
27
# File 'lib/wurk/flow/chain.rb', line 24

def initialize(builder)
  @builder  = builder
  @previous = nil
end

Instance Method Details

#job(klass) ⇒ Flow::Node

Add the next step.

pipe: nil on the first step is exactly pipe: not being passed — Builder#job treats them the same — so there is no first-step branch to get wrong.

Returns:

  • (Flow::Node)

    the step, usable as a depends_on: elsewhere in the same block — a chain is still a graph, so a branch off it is legal and is what the underlying Builder would have built.



37
38
39
# File 'lib/wurk/flow/chain.rb', line 37

def job(klass, *, **)
  @previous = @builder.job(klass, *, pipe: @previous, **)
end