Class: Smith::Workflow::SplitStepPersistence::ExecutionBindingSnapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/smith/workflow/split_step_persistence/execution_binding_snapshot.rb

Constant Summary collapse

MAX_NESTED_WORKFLOWS =
128
MAX_TRANSITIONS =
10_000

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transition, workflow_class:, selected_agent: nil) ⇒ ExecutionBindingSnapshot

Returns a new instance of ExecutionBindingSnapshot.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/smith/workflow/split_step_persistence/execution_binding_snapshot.rb', line 21

def initialize(transition, workflow_class:, selected_agent: nil)
  @transition = transition
  @workflow_class = workflow_class
  @selected_agent = selected_agent
  @bindings = ExecutionBindingCollector.new
  @visited_workflows = {}.compare_by_identity
  @visited_workflows[workflow_class] = true
  @workflow_snapshots = {}.compare_by_identity
  @workflow_queue = []
  @workflow_queue_index = 0
  @transition_count = 0
end

Class Method Details

.capture(transition, workflow_class:) ⇒ Object



13
14
15
# File 'lib/smith/workflow/split_step_persistence/execution_binding_snapshot.rb', line 13

def self.capture(transition, workflow_class:)
  new(transition, workflow_class:).capture
end

.capture_agent(transition, workflow_class:, name:, role:) ⇒ Object



17
18
19
# File 'lib/smith/workflow/split_step_persistence/execution_binding_snapshot.rb', line 17

def self.capture_agent(transition, workflow_class:, name:, role:)
  new(transition, workflow_class:, selected_agent: { name:, role: }).capture
end

Instance Method Details

#captureObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/smith/workflow/split_step_persistence/execution_binding_snapshot.rb', line 34

def capture
  if @selected_agent
    @bindings.capture_agent(
      @selected_agent.fetch(:name),
      workflow_class: @workflow_class,
      transition: @transition,
      role: @selected_agent.fetch(:role)
    )
  else
    capture_transition(@transition, workflow_class: @workflow_class)
    drain_workflow_queue
  end
  @bindings.resolve!
  @bindings.freeze
  @workflow_snapshots.freeze
  freeze
end

#each_agent_bindingObject



56
57
58
# File 'lib/smith/workflow/split_step_persistence/execution_binding_snapshot.rb', line 56

def each_agent_binding(&)
  @bindings.each(&)
end

#fetch!(name, workflow_class:, transition_name:, role:) ⇒ Object



52
53
54
# File 'lib/smith/workflow/split_step_persistence/execution_binding_snapshot.rb', line 52

def fetch!(name, workflow_class:, transition_name:, role:)
  @bindings.fetch!(name, workflow_class:, transition_name:, role:)
end

#verify_workflow!(workflow_class) ⇒ Object



60
61
62
63
64
65
# File 'lib/smith/workflow/split_step_persistence/execution_binding_snapshot.rb', line 60

def verify_workflow!(workflow_class)
  snapshot = @workflow_snapshots.fetch(workflow_class) do
    raise WorkflowError, "execution authorization does not contain nested workflow #{workflow_class}"
  end
  snapshot.verify!
end