Class: Attr::Gather::Workflow::TaskGraph Private

Inherits:
Object
  • Object
show all
Includes:
TSort
Defined in:
lib/attr/gather/workflow/task_graph.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: InvalidTaskDepedencyError, UnfinishableError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tasks: []) ⇒ TaskGraph

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TaskGraph.



19
20
21
22
# File 'lib/attr/gather/workflow/task_graph.rb', line 19

def initialize(tasks: [])
  @tasks_hash = {}
  tasks.each { |t| self << t }
end

Instance Attribute Details

#tasks_hashObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
# File 'lib/attr/gather/workflow/task_graph.rb', line 17

def tasks_hash
  @tasks_hash
end

Instance Method Details

#<<(hash) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/attr/gather/workflow/task_graph.rb', line 24

def <<(hash)
  name, depends_on = hash.values_at :name, :depends_on
  task = build_task(name, depends_on)
  validate_for_insert!(task)

  registered_tasks.each do |t|
    tasks_hash[t] << task if t.depends_on?(task)
    tasks_hash[t].uniq!
  end

  tasks_hash[task] = all_dependencies_for_task(task)
end

#each_batchObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/attr/gather/workflow/task_graph.rb', line 43

def each_batch
  return enum_for(:each_batch) unless block_given?

  to_execute = tsort

  until to_execute.empty?
    batch = to_execute.take_while do |task|
      task.fullfilled_given_remaining_tasks?(to_execute)
    end

    to_execute -= batch

    validate_finishable!(batch, to_execute)

    yield batch
  end
end

#runnable_tasksObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
40
41
# File 'lib/attr/gather/workflow/task_graph.rb', line 37

def runnable_tasks
  tsort.take_while do |task|
    task.fullfilled_given_remaining_tasks?(registered_tasks)
  end
end

#to_dot(preview: false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



67
68
69
70
# File 'lib/attr/gather/workflow/task_graph.rb', line 67

def to_dot(preview: false)
  serializer = DotSerializer.new(self)
  preview ? serializer.preview : serializer.to_dot
end

#to_hObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



63
64
65
# File 'lib/attr/gather/workflow/task_graph.rb', line 63

def to_h
  tasks_hash
end