Class: Ask::Graph::Runner
- Inherits:
-
Object
- Object
- Ask::Graph::Runner
- Defined in:
- lib/ask/graph/runner.rb
Overview
Executes the declared steps of a graph, managing checkpointing, condition evaluation, parallel execution, timeouts, retries, lifecycle hooks, and human-in-the-loop pauses.
Instance Attribute Summary collapse
-
#declarations ⇒ Object
readonly
Returns the value of attribute declarations.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #checkpoint_each!(index) ⇒ Object
-
#initialize(declarations, storage: nil, hooks: { before_step: [], after_step: [], on_failure: [] }, graph_instance: nil, step_timeout: nil, workflow_timeout: nil) ⇒ Runner
constructor
A new instance of Runner.
- #resume(context, input:) ⇒ Object
- #resume_index_for(items) ⇒ Object
- #run(context) ⇒ Object
Constructor Details
#initialize(declarations, storage: nil, hooks: { before_step: [], after_step: [], on_failure: [] }, graph_instance: nil, step_timeout: nil, workflow_timeout: nil) ⇒ Runner
Returns a new instance of Runner.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ask/graph/runner.rb', line 32 def initialize(declarations, storage: nil, hooks: { before_step: [], after_step: [], on_failure: [] }, graph_instance: nil, step_timeout: nil, workflow_timeout: nil) @declarations = declarations @store = storage @hooks = hooks @graph = graph_instance @step_timeout = step_timeout @workflow_timeout = workflow_timeout @completed_steps = [] end |
Instance Attribute Details
#declarations ⇒ Object (readonly)
Returns the value of attribute declarations.
24 25 26 |
# File 'lib/ask/graph/runner.rb', line 24 def declarations @declarations end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
24 25 26 |
# File 'lib/ask/graph/runner.rb', line 24 def store @store end |
Instance Method Details
#checkpoint_each!(index) ⇒ Object
67 68 69 70 |
# File 'lib/ask/graph/runner.rb', line 67 def checkpoint_each!(index) key = each_checkpoint_key @store.set(key, index.to_s) end |
#resume(context, input:) ⇒ Object
56 57 58 59 |
# File 'lib/ask/graph/runner.rb', line 56 def resume(context, input:) context.resume_input = input run(context) end |
#resume_index_for(items) ⇒ Object
61 62 63 64 65 |
# File 'lib/ask/graph/runner.rb', line 61 def resume_index_for(items) key = each_checkpoint_key raw = @store.get(key) raw ? raw.to_i : nil end |
#run(context) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/ask/graph/runner.rb', line 46 def run(context) if @workflow_timeout ::Timeout.timeout(@workflow_timeout) { run_steps(context) } else run_steps(context) end rescue ::Timeout::Error raise WorkflowTimeout, "workflow timed out after #{@workflow_timeout}s" end |