Class: MARS::Workflows::Parallel

Inherits:
Runnable
  • Object
show all
Defined in:
lib/mars/workflows/parallel.rb

Instance Attribute Summary

Attributes inherited from Runnable

#formatter, #name, #state

Instance Method Summary collapse

Methods inherited from Runnable

formatter, step_name

Methods included from Hooks

included, #run_after_hooks, #run_before_hooks

Constructor Details

#initialize(name, steps:, aggregator: nil, **kwargs) ⇒ Parallel

Returns a new instance of Parallel.



6
7
8
9
10
11
# File 'lib/mars/workflows/parallel.rb', line 6

def initialize(name, steps:, aggregator: nil, **kwargs)
  super(name: name, **kwargs)

  @steps = steps
  @aggregator = aggregator || Aggregator.new("#{name} Aggregator")
end

Instance Method Details

#run(context) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/mars/workflows/parallel.rb', line 13

def run(context)
  context = ensure_context(context)
  child_contexts = []
  results = execute_steps(context, child_contexts)

  context.merge(child_contexts)
  context.current_input = results
  aggregator.run(context)
end