Class: Roast::Workflow::StepExecutorCoordinator

Inherits:
Object
  • Object
show all
Defined in:
lib/roast/workflow/step_executor_coordinator.rb

Overview

Coordinates the execution of different types of steps

This class is responsible for routing steps to their appropriate executors based on the step type. It acts as a central dispatcher that determines which execution strategy to use for each step.

Current Architecture:

  • WorkflowExecutor.execute_steps still handles basic routing for backward compatibility

  • This coordinator is used by WorkflowExecutor.execute_step for named steps

  • Some step types (parallel) use the StepExecutorFactory pattern

  • Other step types use direct execution methods

TODO: Future refactoring should move all execution logic from WorkflowExecutor to this coordinator and use the factory pattern consistently for all step types.

Instance Method Summary collapse

Constructor Details

#initialize(context:, dependencies:) ⇒ StepExecutorCoordinator

Returns a new instance of StepExecutorCoordinator.



20
21
22
23
# File 'lib/roast/workflow/step_executor_coordinator.rb', line 20

def initialize(context:, dependencies:)
  @context = context
  @dependencies = dependencies
end

Instance Method Details

#execute(step, options = {}) ⇒ Object

Execute a step based on its type

Parameters:

  • step (String, Hash, Array)

    The step to execute

  • options (Hash) (defaults to: {})

    Execution options

Returns:

  • (Object)

    The result of the step execution



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/step_executor_coordinator.rb', line 55

def execute(step, options = {})
  step_type = StepTypeResolver.resolve(step, @context)
  step_name = StepTypeResolver.extract_name(step)

  Thread.current[:current_step_name] = step_name if step_name
  Thread.current[:workflow_metadata] = @context.workflow.

  case step_type
  when StepTypeResolver::COMMAND_STEP
    # Command steps should also go through interpolation
    execute_string_step(step, options)
  when StepTypeResolver::AGENT_STEP
    execute_agent_step(step, options)
  when StepTypeResolver::GLOB_STEP
    execute_glob_step(step, options)
  when StepTypeResolver::ITERATION_STEP
    execute_iteration_step(step, options)
  when StepTypeResolver::CONDITIONAL_STEP
    execute_conditional_step(step, options)
  when StepTypeResolver::CASE_STEP
    execute_case_step(step, options)
  when StepTypeResolver::INPUT_STEP
    execute_input_step(step, options)
  when StepTypeResolver::HASH_STEP
    execute_hash_step(step, options)
  when StepTypeResolver::PARALLEL_STEP
    # Use factory for parallel steps
    executor = StepExecutorFactory.for(step, workflow_executor)
    executor.execute(step)
  when StepTypeResolver::STRING_STEP
    execute_string_step(step, options)
  else
    execute_standard_step(step, options)
  end
end

#execute_step(step, options = {}) ⇒ Object

Execute a single step (alias for compatibility)



47
48
49
# File 'lib/roast/workflow/step_executor_coordinator.rb', line 47

def execute_step(step, options = {})
  execute(step, options)
end

#execute_steps(workflow_steps) ⇒ Object

Execute a list of steps



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/roast/workflow/step_executor_coordinator.rb', line 26

def execute_steps(workflow_steps)
  workflow_steps.each_with_index do |step, index|
    is_last_step = (index == workflow_steps.length - 1)
    case step
    when Hash
      execute(step, is_last_step:)
    when Array
      execute(step, is_last_step:)
    when String
      execute(step, is_last_step:)
      # Handle pause after string steps
      if @context.workflow.pause_step_name == step
        Kernel.binding.irb # rubocop:disable Lint/Debugger
      end
    else
      execute_custom_step(step, is_last_step: is_last_step)
    end
  end
end