Class: LittleGhost::Workflow::Invocation
- Inherits:
-
Object
- Object
- LittleGhost::Workflow::Invocation
- Defined in:
- lib/little_ghost/workflow.rb
Overview
Hold one lazy Assembly call inside a workflow composition. Workflow implementations normally use only its output method or return the object as the final invocation.
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#close ⇒ Object
:nodoc:.
-
#consumed? ⇒ Boolean
:nodoc:.
-
#each(checkpoint: nil) ⇒ Object
:nodoc:.
-
#initialize(reference:, participant:, input:, history:, context:, policies:, owner:) ⇒ Invocation
constructor
:nodoc:.
-
#output ⇒ Object
Consumes this invocation when necessary and returns RunResult#output.
Constructor Details
#initialize(reference:, participant:, input:, history:, context:, policies:, owner:) ⇒ Invocation
:nodoc:
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/little_ghost/workflow.rb', line 61 def initialize(reference:, participant:, input:, history:, context:, policies:, owner:) # :nodoc: @reference = reference @participant = participant @input = input @history = history @context = context @policies = policies @owner = owner @mutex = Mutex.new @consumed = false @closed = false end |
Instance Attribute Details
#result ⇒ Object (readonly)
:nodoc:
59 60 61 |
# File 'lib/little_ghost/workflow.rb', line 59 def result @result end |
Instance Method Details
#close ⇒ Object
:nodoc:
121 122 123 124 125 126 127 |
# File 'lib/little_ghost/workflow.rb', line 121 def close # :nodoc: @mutex.synchronize do return if @closed @closed = true end end |
#consumed? ⇒ Boolean
:nodoc:
117 118 119 |
# File 'lib/little_ghost/workflow.rb', line 117 def consumed? # :nodoc: @mutex.synchronize { @consumed } end |
#each(checkpoint: nil) ⇒ Object
:nodoc:
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/little_ghost/workflow.rb', line 74 def each(checkpoint: nil) # :nodoc: return enum_for(__method__, checkpoint:) unless block_given? @mutex.synchronize do raise Error, "workflow invocation is already closed" if @closed raise ProtocolError, "workflow invocation was already consumed" if @consumed @consumed = true end execution = @owner.send( :execute_workflow_invocation, reference: @reference, participant: @participant, input: @input, history: @history, context: @context, policies: @policies, checkpoint: ) { |event| yield event } @result = execution.result @step = execution.step @steps = execution.result.steps execution.events.each do |event| yield event end @result end |
#output ⇒ Object
Consumes this invocation when necessary and returns RunResult#output.
A structured agent returns its validated value; an ordinary agent returns response text. Intermediate usage is recorded for the workflow total.
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/little_ghost/workflow.rb', line 106 def output @intermediate = true unless consumed? each do |event| @owner.send(:emit_workflow_event, event) if event.type.to_s.start_with?("assembly_") end @owner.send(:record_workflow_steps, @steps) end result&.output end |