Class: Roast::Workflow::ReplayHandler
- Inherits:
-
Object
- Object
- Roast::Workflow::ReplayHandler
- Defined in:
- lib/roast/workflow/replay_handler.rb
Overview
Handles replay functionality for workflows Manages skipping to specific steps and loading previous state
Instance Attribute Summary collapse
-
#processed ⇒ Object
readonly
Returns the value of attribute processed.
Instance Method Summary collapse
-
#initialize(workflow, state_repository: nil) ⇒ ReplayHandler
constructor
A new instance of ReplayHandler.
- #load_state_and_restore(step_name, timestamp: nil) ⇒ Object
- #process_replay(steps, replay_option) ⇒ Object
Constructor Details
#initialize(workflow, state_repository: nil) ⇒ ReplayHandler
Returns a new instance of ReplayHandler.
10 11 12 13 14 |
# File 'lib/roast/workflow/replay_handler.rb', line 10 def initialize(workflow, state_repository: nil) @workflow = workflow @state_repository = state_repository || StateRepositoryFactory.create(workflow.storage_type) @processed = false end |
Instance Attribute Details
#processed ⇒ Object (readonly)
Returns the value of attribute processed.
8 9 10 |
# File 'lib/roast/workflow/replay_handler.rb', line 8 def processed @processed end |
Instance Method Details
#load_state_and_restore(step_name, timestamp: nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/roast/workflow/replay_handler.rb', line 34 def load_state_and_restore(step_name, timestamp: nil) state_data = if $stderr.puts "Looking for state before '#{step_name}' in session #{timestamp}..." @state_repository.load_state_before_step(@workflow, step_name, timestamp: ) else $stderr.puts "Looking for state before '#{step_name}' in most recent session..." @state_repository.load_state_before_step(@workflow, step_name) end if state_data $stderr.puts "Successfully loaded state with data from previous step" restore_workflow_state(state_data) else session_info = ? " in session #{timestamp}" : "" $stderr.puts "Could not find suitable state data from a previous step to '#{step_name}'#{session_info}." $stderr.puts "Will run workflow from '#{step_name}' without prior context." end state_data end |
#process_replay(steps, replay_option) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/roast/workflow/replay_handler.rb', line 16 def process_replay(steps, replay_option) return steps unless replay_option && !@processed , step_name = parse_replay_option(replay_option) skip_index = StepFinder.find_index(steps, step_name) if skip_index $stderr.puts "Replaying from step: #{step_name}#{timestamp ? " (session: #{timestamp})" : ""}" @workflow. = if && @workflow.respond_to?(:session_timestamp=) steps = load_state_and_get_remaining_steps(steps, skip_index, step_name, ) else $stderr.puts "Step #{step_name} not found in workflow, running from beginning" end @processed = true steps end |