Class: Roast::Workflow::StateManager
- Inherits:
-
Object
- Object
- Roast::Workflow::StateManager
- Defined in:
- lib/roast/workflow/state_manager.rb
Overview
Manages workflow state persistence and restoration
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#workflow ⇒ Object
readonly
Returns the value of attribute workflow.
Instance Method Summary collapse
-
#initialize(workflow, logger: nil, state_repository: nil, storage_type: nil) ⇒ StateManager
constructor
A new instance of StateManager.
-
#save_state(step_name, step_result) ⇒ Object
Save the current state after a step execution.
-
#should_save_state? ⇒ Boolean
Check if state should be saved for the current workflow.
Constructor Details
#initialize(workflow, logger: nil, state_repository: nil, storage_type: nil) ⇒ StateManager
Returns a new instance of StateManager.
9 10 11 12 13 |
# File 'lib/roast/workflow/state_manager.rb', line 9 def initialize(workflow, logger: nil, state_repository: nil, storage_type: nil) @workflow = workflow @logger = logger @state_repository = state_repository || StateRepositoryFactory.create(storage_type) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/roast/workflow/state_manager.rb', line 7 def logger @logger end |
#workflow ⇒ Object (readonly)
Returns the value of attribute workflow.
7 8 9 |
# File 'lib/roast/workflow/state_manager.rb', line 7 def workflow @workflow end |
Instance Method Details
#save_state(step_name, step_result) ⇒ Object
Save the current state after a step execution
19 20 21 22 23 24 25 26 27 |
# File 'lib/roast/workflow/state_manager.rb', line 19 def save_state(step_name, step_result) return unless should_save_state? state_data = build_state_data(step_name, step_result) @state_repository.save_state(workflow, step_name, state_data) rescue => e # Don't fail the workflow if state saving fails log_warning("Failed to save workflow state: #{e.}") end |
#should_save_state? ⇒ Boolean
Check if state should be saved for the current workflow
32 33 34 |
# File 'lib/roast/workflow/state_manager.rb', line 32 def should_save_state? workflow.respond_to?(:session_name) && workflow.session_name end |