Class: Phronomy::Workflow

Inherits:
Object
  • Object
show all
Includes:
Runnable
Defined in:
lib/phronomy/workflow.rb,
lib/phronomy/workflow/phase_machine_builder.rb

Overview

StateChart-style Workflow definition DSL.

Defined Under Namespace

Classes: Builder, PhaseMachineBuilder

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Runnable

#batch, #trace

Constructor Details

#initialize(runner) ⇒ Workflow

Returns a new instance of Workflow.



17
18
19
# File 'lib/phronomy/workflow.rb', line 17

def initialize(runner)
  @runner = runner
end

Class Method Details

.define(context_class, state_store: nil, &block) ⇒ Object



11
12
13
14
15
# File 'lib/phronomy/workflow.rb', line 11

def self.define(context_class, state_store: nil, &block)
  builder = Builder.new(context_class, state_store: state_store)
  builder.instance_eval(&block)
  builder.build
end

Instance Method Details

#invoke(input, config: {}, invocation_context: nil) ⇒ Object



21
22
23
24
# File 'lib/phronomy/workflow.rb', line 21

def invoke(input, config: {}, invocation_context: nil)
  config = _apply_invocation_context(config, invocation_context) if invocation_context
  @runner.invoke(input, config: config)
end

#invoke_async(input, config: {}, invocation_context: nil) ⇒ Object



26
27
28
29
# File 'lib/phronomy/workflow.rb', line 26

def invoke_async(input, config: {}, invocation_context: nil)
  config = _apply_invocation_context(config, invocation_context) if invocation_context
  @runner.invoke_deferred(input, config: config)
end

#resume(state:, input: nil) ⇒ Object



36
37
38
# File 'lib/phronomy/workflow.rb', line 36

def resume(state:, input: nil)
  @runner.resume(state: state, input: input)
end

#send_event(state:, event:, input: nil) ⇒ Object



40
41
42
# File 'lib/phronomy/workflow.rb', line 40

def send_event(state:, event:, input: nil)
  @runner.send_event(state: state, event: event, input: input)
end

#signal(thread_id:, event:, payload: nil) ⇒ Boolean

Sends an event to an active Workflow session without blocking.

This method is safe to call from an Agent/Tool listener running on the EventLoop thread because it only enqueues a later dispatch.

Returns:

  • (Boolean)

    true when admitted; false when the session is not live or Runtime shutdown has begun



52
53
54
55
56
57
58
# File 'lib/phronomy/workflow.rb', line 52

def signal(thread_id:, event:, payload: nil)
  @runner.signal(
    thread_id: thread_id,
    event: event,
    payload: payload
  )
end

#stream(input, config: {}, invocation_context: nil, &block) ⇒ Object



31
32
33
34
# File 'lib/phronomy/workflow.rb', line 31

def stream(input, config: {}, invocation_context: nil, &block)
  config = _apply_invocation_context(config, invocation_context) if invocation_context
  @runner.stream(input, config: config, &block)
end