Class: Distribot::Plan
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#tasks ⇒ Object
Returns the value of attribute tasks.
Class Method Summary collapse
Instance Method Summary collapse
- #group(name, options = {}, &block) ⇒ Object
-
#initialize(name) ⇒ Plan
constructor
A new instance of Plan.
- #schedule ⇒ Object
- #task(name, options = {}, &block) ⇒ Object
Constructor Details
#initialize(name) ⇒ Plan
Returns a new instance of Plan.
8 9 10 11 |
# File 'lib/distribot/plan.rb', line 8 def initialize(name) @name = name @tasks = [ ] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/distribot/plan.rb', line 7 def name @name end |
#tasks ⇒ Object
Returns the value of attribute tasks.
7 8 9 |
# File 'lib/distribot/plan.rb', line 7 def tasks @tasks end |
Class Method Details
.all ⇒ Object
44 45 46 47 |
# File 'lib/distribot/plan.rb', line 44 def self.all @@plans ||= [ ] @@plans end |
.reset! ⇒ Object
49 50 51 |
# File 'lib/distribot/plan.rb', line 49 def self.reset! @@plans = [ ] end |
Instance Method Details
#group(name, options = {}, &block) ⇒ Object
13 14 15 16 17 |
# File 'lib/distribot/plan.rb', line 13 def group(name, ={}, &block) task_group = TaskGroup.new(name, [:depends_on]) task_group.instance_eval(&block) self.tasks += task_group.tasks end |
#schedule ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/distribot/plan.rb', line 28 def schedule grouped = tsort_each_child.map{|_parent, tasks| tasks} grouped.each_with_index.map do |group, idx| info = { name: 'phase %d/%d' % [ idx + 1, grouped.count ], handlers: group.map(&:handler_data) } if grouped[idx + 1] info[:transitions_to] = 'phase %d/%d' % [ idx + 2, grouped.count ] end info.merge!(is_initial: true) if idx == 0 info.merge!(is_final: true) if idx + 1 == grouped.count info end end |
#task(name, options = {}, &block) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/distribot/plan.rb', line 19 def task(name, ={}, &block) if tasks.select{ |task| task.name.to_s == name.to_s }.any? raise TaskConfigError.new "The name '%s' is already taken" end task = Task.new(name, [:depends_on]) task.instance_eval(&block) tasks << task end |