Module: Dynflow::Action::WithPollingSubPlans
- Defined in:
- lib/dynflow/action/with_polling_sub_plans.rb
Constant Summary collapse
- REFRESH_INTERVAL =
10
- Poll =
Algebrick.atom
Instance Method Summary collapse
- #initiate ⇒ Object
- #notify_on_finish(_sub_plans) ⇒ Object
- #ping(_suspended_action = nil) ⇒ Object
- #poll ⇒ Object
- #recalculate_counts ⇒ Object
- #resume ⇒ Object
- #run(event = nil) ⇒ Object
- #suspend_and_ping ⇒ Object
- #wait_for_sub_plans(sub_plans) ⇒ Object
Instance Method Details
#initiate ⇒ Object
22 23 24 25 |
# File 'lib/dynflow/action/with_polling_sub_plans.rb', line 22 def initiate ping super end |
#notify_on_finish(_sub_plans) ⇒ Object
51 52 53 |
# File 'lib/dynflow/action/with_polling_sub_plans.rb', line 51 def notify_on_finish(_sub_plans) suspend end |
#ping(_suspended_action = nil) ⇒ Object
60 61 62 |
# File 'lib/dynflow/action/with_polling_sub_plans.rb', line 60 def ping(_suspended_action = nil) plan_event(Poll, REFRESH_INTERVAL) end |
#poll ⇒ Object
17 18 19 20 |
# File 'lib/dynflow/action/with_polling_sub_plans.rb', line 17 def poll recalculate_counts try_to_finish || suspend_and_ping end |
#recalculate_counts ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/dynflow/action/with_polling_sub_plans.rb', line 64 def recalculate_counts total = sub_plans_count failed = sub_plans_count('state' => %w(paused stopped), 'result' => 'error') success = sub_plans_count('state' => 'stopped', 'result' => 'success') output.update(:total_count => total - output.fetch(:resumed_count, 0), :pending_count => total - failed - success, :failed_count => failed - output.fetch(:resumed_count, 0), :success_count => success) end |
#resume ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dynflow/action/with_polling_sub_plans.rb', line 32 def resume if sub_plans.all? { |sub_plan| sub_plan.error_in_plan? } output[:resumed_count] ||= 0 output[:resumed_count] += output[:failed_count] # We're starting over and need to reset the counts %w(total failed pending success).each { |key| output.delete("#{key}_count".to_sym) } initiate else if self.is_a?(::Dynflow::Action::WithBulkSubPlans) && can_spawn_next_batch? # Not everything was spawned ping spawn_plans suspend else poll end end end |
#run(event = nil) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/dynflow/action/with_polling_sub_plans.rb', line 8 def run(event = nil) case event when Poll poll else super(event) end end |
#suspend_and_ping ⇒ Object
55 56 57 58 |
# File 'lib/dynflow/action/with_polling_sub_plans.rb', line 55 def suspend_and_ping ping suspend end |
#wait_for_sub_plans(sub_plans) ⇒ Object
27 28 29 30 |
# File 'lib/dynflow/action/with_polling_sub_plans.rb', line 27 def wait_for_sub_plans(sub_plans) increase_counts(sub_plans.count, 0) suspend end |