Class: RubyReactor::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_reactor/executor.rb,
lib/ruby_reactor/executor/graph_manager.rb,
lib/ruby_reactor/executor/retry_manager.rb,
lib/ruby_reactor/executor/step_executor.rb,
lib/ruby_reactor/executor/result_handler.rb,
lib/ruby_reactor/executor/input_validator.rb,
lib/ruby_reactor/executor/compensation_manager.rb

Defined Under Namespace

Classes: CompensationManager, GraphManager, InputValidator, ResultHandler, RetryManager, StepExecutor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reactor_class, inputs = {}, context = nil) ⇒ Executor

Returns a new instance of Executor.



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/ruby_reactor/executor.rb', line 15

def initialize(reactor_class, inputs = {}, context = nil)
  @reactor_class = reactor_class
  @context = context || Context.new(inputs, reactor_class)
  @dependency_graph = DependencyGraph.new
  @compensation_manager = CompensationManager.new(@context)
  @retry_manager = RetryManager.new(@context)
  @result_handler = ResultHandler.new(
    context: @context,
    compensation_manager: @compensation_manager,
    dependency_graph: @dependency_graph
  )
  @step_executor = StepExecutor.new(
    context: @context,
    dependency_graph: @dependency_graph,
    reactor_class: @reactor_class,
    managers: {
      retry_manager: @retry_manager,
      result_handler: @result_handler,
      compensation_manager: @compensation_manager
    }
  )
  @result = nil
end

Instance Attribute Details

#compensation_managerObject (readonly)

Returns the value of attribute compensation_manager.



12
13
14
# File 'lib/ruby_reactor/executor.rb', line 12

def compensation_manager
  @compensation_manager
end

#contextObject (readonly)

Returns the value of attribute context.



12
13
14
# File 'lib/ruby_reactor/executor.rb', line 12

def context
  @context
end

#dependency_graphObject (readonly)

Returns the value of attribute dependency_graph.



12
13
14
# File 'lib/ruby_reactor/executor.rb', line 12

def dependency_graph
  @dependency_graph
end

#reactor_classObject (readonly)

Returns the value of attribute reactor_class.



12
13
14
# File 'lib/ruby_reactor/executor.rb', line 12

def reactor_class
  @reactor_class
end

#resultObject (readonly)

Returns the value of attribute result.



12
13
14
# File 'lib/ruby_reactor/executor.rb', line 12

def result
  @result
end

#result_handlerObject (readonly)

Returns the value of attribute result_handler.



12
13
14
# File 'lib/ruby_reactor/executor.rb', line 12

def result_handler
  @result_handler
end

#retry_managerObject (readonly)

Returns the value of attribute retry_manager.



12
13
14
# File 'lib/ruby_reactor/executor.rb', line 12

def retry_manager
  @retry_manager
end

#step_executorObject (readonly)

Returns the value of attribute step_executor.



12
13
14
# File 'lib/ruby_reactor/executor.rb', line 12

def step_executor
  @step_executor
end

Instance Method Details

#executeObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby_reactor/executor.rb', line 39

def execute
  input_validator = InputValidator.new(@reactor_class, @context)
  input_validator.validate!

  graph_manager = GraphManager.new(@reactor_class, @dependency_graph, @context)
  graph_manager.build_and_validate!

  @result = @step_executor.execute_all_steps
rescue StandardError => e
  @result = @result_handler.handle_execution_error(e)
end

#execution_traceObject



71
72
73
# File 'lib/ruby_reactor/executor.rb', line 71

def execution_trace
  @context.execution_trace
end

#resume_executionObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ruby_reactor/executor.rb', line 51

def resume_execution
  prepare_for_resume

  if @context.current_step
    execute_current_step_and_continue
  else
    execute_remaining_steps
  end
rescue StandardError => e
  handle_resume_error(e)
end

#undo_stackObject



63
64
65
# File 'lib/ruby_reactor/executor.rb', line 63

def undo_stack
  @compensation_manager.undo_stack
end

#undo_traceObject



67
68
69
# File 'lib/ruby_reactor/executor.rb', line 67

def undo_trace
  @compensation_manager.undo_trace
end