Class: Roast::Workflow::StepExecutors::ParallelStepExecutor
- Inherits:
-
BaseStepExecutor
- Object
- BaseStepExecutor
- Roast::Workflow::StepExecutors::ParallelStepExecutor
- Defined in:
- lib/roast/workflow/step_executors/parallel_step_executor.rb
Instance Method Summary collapse
Methods inherited from BaseStepExecutor
Constructor Details
This class inherits a constructor from Roast::Workflow::StepExecutors::BaseStepExecutor
Instance Method Details
#execute(steps) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/roast/workflow/step_executors/parallel_step_executor.rb', line 7 def execute(steps) # run steps in parallel, don't proceed until all are done threads = steps.map do |sub_step| Thread.new do # Each thread needs its own isolated execution context Thread.current[:step] = sub_step Thread.current[:result] = nil Thread.current[:error] = nil begin # Execute the single step in this thread step_runner.execute_steps([sub_step]) Thread.current[:result] = :success rescue => e Thread.current[:error] = e end end end # Wait for all threads to complete threads.each(&:join) # Check for errors in any thread threads.each_with_index do |thread, _index| if thread[:error] raise thread[:error] end end :success end |