Class: RubyReactor::Executor::CompensationManager
- Inherits:
-
Object
- Object
- RubyReactor::Executor::CompensationManager
- Defined in:
- lib/ruby_reactor/executor/compensation_manager.rb
Instance Attribute Summary collapse
-
#undo_trace ⇒ Object
readonly
Returns the value of attribute undo_trace.
Instance Method Summary collapse
- #add_to_undo_stack(step_info) ⇒ Object
- #handle_step_failure(step_config, error, arguments) ⇒ Object
-
#initialize(context) ⇒ CompensationManager
constructor
A new instance of CompensationManager.
- #rollback_completed_steps ⇒ Object
- #undo_stack ⇒ Object
Constructor Details
#initialize(context) ⇒ CompensationManager
Returns a new instance of CompensationManager.
6 7 8 9 |
# File 'lib/ruby_reactor/executor/compensation_manager.rb', line 6 def initialize(context) @context = context @undo_trace = [] end |
Instance Attribute Details
#undo_trace ⇒ Object (readonly)
Returns the value of attribute undo_trace.
15 16 17 |
# File 'lib/ruby_reactor/executor/compensation_manager.rb', line 15 def undo_trace @undo_trace end |
Instance Method Details
#add_to_undo_stack(step_info) ⇒ Object
17 18 19 |
# File 'lib/ruby_reactor/executor/compensation_manager.rb', line 17 def add_to_undo_stack(step_info) @context.undo_stack << step_info end |
#handle_step_failure(step_config, error, arguments) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby_reactor/executor/compensation_manager.rb', line 21 def handle_step_failure(step_config, error, arguments) # Try compensation compensation_result = compensate_step(step_config, error, arguments) case compensation_result when RubyReactor::Success # Compensation succeeded, continue with rollback rollback_completed_steps RubyReactor.Failure("Step '#{step_config.name}' failed: #{error}") when RubyReactor::Failure # Compensation failed, this is more serious rollback_completed_steps raise Error::CompensationError.new( "Compensation for step '#{step_config.name}' failed: #{compensation_result.error}", step: step_config.name, context: @context, original_error: error ) end end |
#rollback_completed_steps ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ruby_reactor/executor/compensation_manager.rb', line 41 def rollback_completed_steps undo_stack.reverse_each do |step_info| result = @context.with_step(step_info[:step].name) do undo_step(step_info[:step], step_info[:result], step_info[:arguments]) end @undo_trace << { type: :undo, step: step_info[:step].name, result: result, arguments: step_info[:arguments] } end undo_stack.clear end |
#undo_stack ⇒ Object
11 12 13 |
# File 'lib/ruby_reactor/executor/compensation_manager.rb', line 11 def undo_stack @context.undo_stack end |