Class: Wolflow::StructuredSynchronizedMerge

Inherits:
Simple show all
Defined in:
lib/wolflow/structured_synchronized_merge.rb

Instance Attribute Summary

Attributes inherited from Simple

#next_tasks

Attributes inherited from TaskSpec

#connects_to, #id, #name, #prev_tasks, #workflow_spec

Instance Method Summary collapse

Methods inherited from Simple

#build_next_tasks, #choose, #connect, #connects_with, from_hash, #initialize, #inspect, #precedes?, #to_hash, #to_hash_tree, #workflow_spec=

Methods inherited from TaskSpec

#child_of?, #each_ancestor, #each_child, #each_parent, #each_successor, from_hash, inherited, #initialize

Constructor Details

This class inherits a constructor from Wolflow::Simple

Instance Method Details

#join(*task_specs) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wolflow/structured_synchronized_merge.rb', line 5

def join(*task_specs)
  multi_choices = task_specs.map do |task_spec|
    task_spec.each_ancestor.find do |spec|
      spec.is_a?(MultiChoice)
    end or raise(TaskSpecError, "#{task_spec.id} is not from a multi-choice branch")
  end

  raise TaskSpecError, "not branches from the same multi-choice" unless multi_choices.uniq.size == 1

  # @type var multi_choice: MultiChoice
  multi_choice = multi_choices.first

  unless multi_choice.next_tasks.size == multi_choices.size
    raise TaskSpecError,
          "not joining all branches from the common multi-choice"
  end

  task_specs.each { |spec| spec.connect(self) }

  self
end

#on_complete(task) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/wolflow/structured_synchronized_merge.rb', line 27

def on_complete(task)
  parents_with_multi_choice = task.parents.select(&:completed?).filter_map do |parent|
    multi_choice = parent.each_parent.find { |t| t.task_spec.is_a?(MultiChoice) }
    [parent, multi_choice] if multi_choice
  end

  multi_choices = parents_with_multi_choice.map(&:last).uniq

  return unless multi_choices.size == 1

  # @type var multi_choice: Task
  multi_choice = multi_choices.first

  return unless multi_choice.children.size == parents_with_multi_choice.size

  super
end