Class: Fasten::TaskManager
- Inherits:
-
Array
- Object
- Array
- Fasten::TaskManager
- Defined in:
- lib/fasten/task_manager.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#done ⇒ Object
readonly
Returns the value of attribute done.
-
#failed ⇒ Object
readonly
Returns the value of attribute failed.
-
#pending ⇒ Object
readonly
Returns the value of attribute pending.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
Instance Method Summary collapse
- #<<(task) ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(runner:, targets: []) ⇒ TaskManager
constructor
A new instance of TaskManager.
- #next ⇒ Object
- #no_running? ⇒ Boolean
- #no_waiting? ⇒ Boolean
- #push(*items) ⇒ Object
- #running? ⇒ Boolean
- #update(task) ⇒ Object
- #waiting ⇒ Object
- #waiting? ⇒ Boolean
Constructor Details
#initialize(runner:, targets: []) ⇒ TaskManager
Returns a new instance of TaskManager.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fasten/task_manager.rb', line 5 def initialize(runner:, targets: []) super() @map = {} @done = [] @failed = [] @pending = [] @running = [] @targets = targets @waiting = nil @runner = runner end |
Instance Attribute Details
#done ⇒ Object (readonly)
Returns the value of attribute done.
3 4 5 |
# File 'lib/fasten/task_manager.rb', line 3 def done @done end |
#failed ⇒ Object (readonly)
Returns the value of attribute failed.
3 4 5 |
# File 'lib/fasten/task_manager.rb', line 3 def failed @failed end |
#pending ⇒ Object (readonly)
Returns the value of attribute pending.
3 4 5 |
# File 'lib/fasten/task_manager.rb', line 3 def pending @pending end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
3 4 5 |
# File 'lib/fasten/task_manager.rb', line 3 def runner @runner end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
3 4 5 |
# File 'lib/fasten/task_manager.rb', line 3 def running @running end |
#targets ⇒ Object (readonly)
Returns the value of attribute targets.
3 4 5 |
# File 'lib/fasten/task_manager.rb', line 3 def targets @targets end |
Instance Method Details
#<<(task) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/fasten/task_manager.rb', line 26 def <<(task) raise "Object class #{task.class} not allowed" unless task.is_a? Task raise "Task '#{task.name}' already defined" if @map[task.name] @map[task.name] = task @waiting = nil super end |
#failed? ⇒ Boolean
78 79 80 |
# File 'lib/fasten/task_manager.rb', line 78 def failed? !failed.empty? end |
#next ⇒ Object
35 36 37 |
# File 'lib/fasten/task_manager.rb', line 35 def next waiting.shift end |
#no_running? ⇒ Boolean
66 67 68 |
# File 'lib/fasten/task_manager.rb', line 66 def no_running? running.empty? end |
#no_waiting? ⇒ Boolean
62 63 64 |
# File 'lib/fasten/task_manager.rb', line 62 def no_waiting? waiting.empty? end |
#push(*items) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/fasten/task_manager.rb', line 18 def push(*items) items.each do |item| self << item end self end |
#running? ⇒ Boolean
74 75 76 |
# File 'lib/fasten/task_manager.rb', line 74 def running? !running.empty? end |
#update(task) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fasten/task_manager.rb', line 39 def update(task) pending.delete task if task.state == :DONE done << task task.dependants.each { |dependant_task| dependant_task.depends.delete task } move_pending_to_waiting else failed << task end end |
#waiting ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/fasten/task_manager.rb', line 52 def waiting return @waiting if @waiting reset setup_dependencies setup_targets setup_scores move_pending_to_waiting end |
#waiting? ⇒ Boolean
70 71 72 |
# File 'lib/fasten/task_manager.rb', line 70 def waiting? !waiting.empty? end |