module Dynflow::Action::WithPollingSubPlans

Constants

Poll
REFRESH_INTERVAL

Public Instance Methods

initiate() click to toggle source
Calls superclass method
# File lib/dynflow/action/with_polling_sub_plans.rb, line 21
def initiate
  ping suspended_action
  super
end
notify_on_finish(_sub_plans) click to toggle source
# File lib/dynflow/action/with_polling_sub_plans.rb, line 50
def notify_on_finish(_sub_plans)
  suspend
end
ping(suspended_action) click to toggle source
# File lib/dynflow/action/with_polling_sub_plans.rb, line 58
def ping(suspended_action)
  world.clock.ping suspended_action, REFRESH_INTERVAL, Poll
end
poll() click to toggle source
# File lib/dynflow/action/with_polling_sub_plans.rb, line 16
def poll
  recalculate_counts
  try_to_finish || suspend_and_ping
end
recalculate_counts() click to toggle source
# File lib/dynflow/action/with_polling_sub_plans.rb, line 62
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() click to toggle source
# File lib/dynflow/action/with_polling_sub_plans.rb, line 31
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 suspended_action
      spawn_plans
      suspend
    else
      poll
    end
  end
end
run(event = nil) click to toggle source
Calls superclass method
# File lib/dynflow/action/with_polling_sub_plans.rb, line 7
def run(event = nil)
  case event
  when Poll
    poll
  else
    super(event)
  end
end
suspend_and_ping() click to toggle source
# File lib/dynflow/action/with_polling_sub_plans.rb, line 54
def suspend_and_ping
  suspend { |suspended_action| ping suspended_action }
end
wait_for_sub_plans(sub_plans) click to toggle source
# File lib/dynflow/action/with_polling_sub_plans.rb, line 26
def wait_for_sub_plans(sub_plans)
  increase_counts(sub_plans.count, 0)
  suspend
end