@@ -10,33 +10,27 @@ def initialize(name, steps:, aggregator: nil, **kwargs)
1010 @aggregator = aggregator || Aggregator . new ( "#{ name } Aggregator" )
1111 end
1212
13- def run ( input )
14- context = ensure_context ( input )
13+ def run ( context )
14+ context = ensure_context ( context )
1515 errors = [ ]
1616 child_contexts = [ ]
1717 results = execute_steps ( context , errors , child_contexts )
1818
1919 raise AggregateError , errors if errors . any?
2020
2121 context . merge ( child_contexts )
22- aggregate_results ( results )
22+ context . current_input = results
23+ aggregator . run ( context )
2324 end
2425
2526 private
2627
2728 attr_reader :steps , :aggregator
2829
29- def aggregate_results ( results )
30- has_global_halt = results . any? { |r | r . is_a? ( Halt ) && r . global? }
31- unwrapped = results . map { |r | r . is_a? ( Halt ) ? r . result : r }
32- result = aggregator . run ( unwrapped )
33- has_global_halt ? Halt . new ( result , scope : :global ) : result
34- end
35-
3630 def execute_steps ( context , errors , child_contexts )
3731 Async do |workflow |
3832 tasks = steps . map do |step |
39- child_ctx = context . fork
33+ child_ctx = context . fork ( state : step . state )
4034 child_contexts << child_ctx
4135
4236 workflow . async do
@@ -54,17 +48,14 @@ def workflow_step(step, child_ctx)
5448 step . run_before_hooks ( child_ctx )
5549
5650 step_input = step . formatter . format_input ( child_ctx )
57- result = step . run ( step_input )
51+ child_ctx . current_input = step_input
52+
53+ result = step . run ( child_ctx )
5854
59- if result . is_a? ( Halt )
60- step . run_after_hooks ( child_ctx , result )
61- result
62- else
63- formatted = step . formatter . format_output ( result )
64- child_ctx . record ( step . name , formatted )
65- step . run_after_hooks ( child_ctx , formatted )
66- formatted
67- end
55+ formatted = step . formatter . format_output ( result )
56+ child_ctx . record ( step . name , formatted )
57+ step . run_after_hooks ( child_ctx , formatted )
58+ formatted
6859 end
6960
7061 def ensure_context ( input )
0 commit comments