Class: Smith::Workflow::Parallel

Inherits:
Object
  • Object
show all
Defined in:
lib/smith/workflow/parallel.rb,
lib/smith/workflow/parallel/cancellation.rb,
lib/smith/workflow/parallel/root_execution.rb,
lib/smith/workflow/parallel/nested_execution.rb,
lib/smith/workflow/parallel/execution_context.rb,
lib/smith/workflow/parallel/cancellation_signal.rb

Defined Under Namespace

Classes: Cancellation, CancellationSignal, ExecutionContext, NestedExecution, RootExecution

Class Method Summary collapse

Class Method Details

.execute(branches:) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/smith/workflow/parallel.rb', line 31

def self.execute(branches:)
  validate_branch_count!(branches.length)
  context = ExecutionContext.current
  return NestedExecution.new(branches:, context:).call if context

  RootExecution.new(branches:).call
end

.preferred_error(reasons) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/smith/workflow/parallel.rb', line 39

def self.preferred_error(reasons)
  errors = Array(reasons).compact
  errors.find { |error| !error.is_a?(StandardError) } ||
    errors.find { |error| error.is_a?(ToolCaptureFailed) } ||
    errors.find { |error| !error.is_a?(Cancellation) } ||
    errors.first
end

.resolve_branch_count(transition, context) ⇒ Object



14
15
16
17
18
# File 'lib/smith/workflow/parallel.rb', line 14

def self.resolve_branch_count(transition, context)
  count = transition.agent_opts[:count]
  resolved = count.respond_to?(:call) ? count.call(context) : (count || 1)
  validate_branch_count!(resolved)
end

.validate_branch_count!(count) ⇒ Object

Raises:



20
21
22
23
24
25
26
27
28
29
# File 'lib/smith/workflow/parallel.rb', line 20

def self.validate_branch_count!(count)
  unless count.is_a?(Integer) && count.positive?
    raise WorkflowError, "parallel branch count must be a positive integer"
  end

  limit = Smith.config.parallel_branch_limit
  raise WorkflowError, "parallel branch count exceeds configured limit #{limit}" if count > limit

  count
end