Class: Autobuild::RakeTaskParallelism::ProcessingState
- Inherits:
-
Object
- Object
- Autobuild::RakeTaskParallelism::ProcessingState
- Defined in:
- lib/autobuild/parallel.rb
Instance Attribute Summary collapse
-
#active_tasks ⇒ Object
readonly
Returns the value of attribute active_tasks.
-
#priorities ⇒ Object
readonly
Returns the value of attribute priorities.
-
#processed ⇒ Object
readonly
Returns the value of attribute processed.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#reverse_dependencies ⇒ Object
readonly
Returns the value of attribute reverse_dependencies.
-
#started_packages ⇒ Object
readonly
Returns the value of attribute started_packages.
Instance Method Summary collapse
- #active_task?(task) ⇒ Boolean
- #already_processed?(task) ⇒ Boolean
- #find_task ⇒ Object
-
#initialize(reverse_dependencies, completion_callback: proc {}) ⇒ ProcessingState
constructor
A new instance of ProcessingState.
- #mark_as_active(pending_task) ⇒ Object
- #needs_processing?(task) ⇒ Boolean
- #pop ⇒ Object
- #process_finished_task(task) ⇒ Object
- #push(task, base_priority = 1) ⇒ Object
- #ready?(task) ⇒ Boolean
- #trivial_task?(task) ⇒ Boolean
Constructor Details
#initialize(reverse_dependencies, completion_callback: proc {}) ⇒ ProcessingState
Returns a new instance of ProcessingState.
77 78 79 80 81 82 83 84 85 |
# File 'lib/autobuild/parallel.rb', line 77 def initialize(reverse_dependencies, completion_callback: proc {}) @reverse_dependencies = reverse_dependencies @completion_callback = completion_callback @processed = Set.new @active_tasks = Set.new @priorities = Hash.new @started_packages = Hash.new @queue = Hash.new end |
Instance Attribute Details
#active_tasks ⇒ Object (readonly)
Returns the value of attribute active_tasks.
74 75 76 |
# File 'lib/autobuild/parallel.rb', line 74 def active_tasks @active_tasks end |
#priorities ⇒ Object (readonly)
Returns the value of attribute priorities.
74 75 76 |
# File 'lib/autobuild/parallel.rb', line 74 def priorities @priorities end |
#processed ⇒ Object (readonly)
Returns the value of attribute processed.
74 75 76 |
# File 'lib/autobuild/parallel.rb', line 74 def processed @processed end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
74 75 76 |
# File 'lib/autobuild/parallel.rb', line 74 def queue @queue end |
#reverse_dependencies ⇒ Object (readonly)
Returns the value of attribute reverse_dependencies.
74 75 76 |
# File 'lib/autobuild/parallel.rb', line 74 def reverse_dependencies @reverse_dependencies end |
#started_packages ⇒ Object (readonly)
Returns the value of attribute started_packages.
74 75 76 |
# File 'lib/autobuild/parallel.rb', line 74 def started_packages @started_packages end |
Instance Method Details
#active_task?(task) ⇒ Boolean
113 114 115 |
# File 'lib/autobuild/parallel.rb', line 113 def active_task?(task) active_tasks.include?(task) end |
#already_processed?(task) ⇒ Boolean
123 124 125 |
# File 'lib/autobuild/parallel.rb', line 123 def already_processed?(task) task.already_invoked? && !active_task?(task) end |
#find_task ⇒ Object
96 97 98 99 100 101 |
# File 'lib/autobuild/parallel.rb', line 96 def find_task if (task = queue.min_by { |_t, p| p }) priorities[task.first] = task.last task.first end end |
#mark_as_active(pending_task) ⇒ Object
109 110 111 |
# File 'lib/autobuild/parallel.rb', line 109 def mark_as_active(pending_task) active_tasks << pending_task end |
#needs_processing?(task) ⇒ Boolean
127 128 129 |
# File 'lib/autobuild/parallel.rb', line 127 def needs_processing?(task) !task.already_invoked? && !active_task?(task) end |
#pop ⇒ Object
103 104 105 106 107 |
# File 'lib/autobuild/parallel.rb', line 103 def pop candidate = find_task queue.delete(candidate) candidate end |
#process_finished_task(task) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/autobuild/parallel.rb', line 131 def process_finished_task(task) active_tasks.delete(task) processed << task reverse_dependencies[task].each do |candidate| if needs_processing?(candidate) && ready?(candidate) push(candidate, priorities[task]) end end @completion_callback.call(task) end |
#push(task, base_priority = 1) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/autobuild/parallel.rb', line 87 def push(task, base_priority = 1) if task.respond_to?(:package) started_packages[task.package] ||= -started_packages.size queue[task] = started_packages[task.package] else queue[task] = base_priority end end |
#ready?(task) ⇒ Boolean
117 118 119 120 121 |
# File 'lib/autobuild/parallel.rb', line 117 def ready?(task) task.prerequisite_tasks.all? do |t| already_processed?(t) end end |
#trivial_task?(task) ⇒ Boolean
143 144 145 146 |
# File 'lib/autobuild/parallel.rb', line 143 def trivial_task?(task) (task.kind_of?(Autobuild::SourceTreeTask) || task.kind_of?(Rake::FileTask)) && task.actions.empty? end |