Class: Roast::Workflow::IterationExecutor
- Inherits:
-
Object
- Object
- Roast::Workflow::IterationExecutor
- Defined in:
- lib/roast/workflow/iteration_executor.rb
Overview
Handles execution of iteration steps (repeat and each)
Instance Method Summary collapse
- #execute_each(each_config) ⇒ Object
- #execute_repeat(repeat_config) ⇒ Object
-
#initialize(workflow, context_path, state_manager, config_hash = {}) ⇒ IterationExecutor
constructor
A new instance of IterationExecutor.
Constructor Details
#initialize(workflow, context_path, state_manager, config_hash = {}) ⇒ IterationExecutor
Returns a new instance of IterationExecutor.
7 8 9 10 11 12 |
# File 'lib/roast/workflow/iteration_executor.rb', line 7 def initialize(workflow, context_path, state_manager, config_hash = {}) @workflow = workflow @context_path = context_path @state_manager = state_manager @config_hash = config_hash end |
Instance Method Details
#execute_each(each_config) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/roast/workflow/iteration_executor.rb', line 52 def execute_each(each_config) $stderr.puts "Executing each step: #{each_config.inspect}" # Extract parameters from the each configuration collection_expr = each_config["each"] variable_name = each_config["as"] steps = each_config["steps"] # Verify required parameters raise WorkflowExecutor::ConfigurationError, "Missing collection expression in each configuration" unless collection_expr raise WorkflowExecutor::ConfigurationError, "Missing 'as' variable name in each configuration" unless variable_name raise WorkflowExecutor::ConfigurationError, "Missing 'steps' in each configuration" unless steps # Create and execute an EachStep each_step = EachStep.new( @workflow, collection_expr: collection_expr, variable_name: variable_name, steps: steps, name: "each_#{variable_name}", context_path: @context_path, config_hash: @config_hash, ) # Apply configuration if provided apply_step_configuration(each_step, each_config) results = each_step.call # Store results in workflow output step_name = "each_#{variable_name}" @workflow.output[step_name] = results # Save state @state_manager.save_state(step_name, results) results end |
#execute_repeat(repeat_config) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/roast/workflow/iteration_executor.rb', line 14 def execute_repeat(repeat_config) $stderr.puts "Executing repeat step: #{repeat_config.inspect}" # Extract parameters from the repeat configuration steps = repeat_config["steps"] until_condition = repeat_config["until"] max_iterations = repeat_config["max_iterations"] || BaseIterationStep::DEFAULT_MAX_ITERATIONS # Verify required parameters raise WorkflowExecutor::ConfigurationError, "Missing 'steps' in repeat configuration" unless steps raise WorkflowExecutor::ConfigurationError, "Missing 'until' condition in repeat configuration" unless until_condition # Create and execute a RepeatStep repeat_step = RepeatStep.new( @workflow, steps: steps, until_condition: until_condition, max_iterations: max_iterations, name: "repeat_#{@workflow.output.size}", context_path: @context_path, config_hash: @config_hash, ) # Apply configuration if provided apply_step_configuration(repeat_step, repeat_config) results = repeat_step.call # Store results in workflow output step_name = "repeat_#{until_condition.gsub(/[^a-zA-Z0-9_]/, "_")}" @workflow.output[step_name] = results # Save state @state_manager.save_state(step_name, results) results end |