module Dynflow::Action::WithBulkSubPlans

Constants

DEFAULT_BATCH_SIZE
PlanNextBatch

Public Instance Methods

batch(from, size) click to toggle source

Should return a slice of size items starting from item with index from

# File lib/dynflow/action/with_bulk_sub_plans.rb, line 8
def batch(from, size)
  raise NotImplementedError
end
batch_size() click to toggle source
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 46
def batch_size
  DEFAULT_BATCH_SIZE
end
cancel!() click to toggle source
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 65
def cancel!
  # Count the not-yet-planned tasks as failed
  output[:failed_count] += total_count - output[:planned_count]
  if uses_concurrency_control
    # Tell the throttle limiter to cancel the tasks its managing
    world.throttle_limiter.cancel!(execution_plan_id)
  else
    # Just stop the tasks which were not started yet
    sub_plans(:state => 'planned').each { |sub_plan| sub_plan.update_state(:stopped) }
  end
  running = sub_plans(:state => 'running')
  # Pass the cancel event to running sub plans if they can be cancelled
  running.each { |sub_plan| sub_plan.cancel! if sub_plan.cancellable? }
  suspend
end
current_batch() click to toggle source

Returns the items in the current batch

# File lib/dynflow/action/with_bulk_sub_plans.rb, line 40
def current_batch
  start_position = output[:planned_count]
  size = start_position + batch_size > total_count ? total_count - start_position : batch_size
  batch(start_position, size)
end
increase_counts(planned, failed) click to toggle source
Calls superclass method
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 29
def increase_counts(planned, failed)
  super(planned, failed, false)
  output[:planned_count] += planned
end
initiate() click to toggle source
Calls superclass method
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 23
def initiate
  output[:planned_count] = 0
  output[:total_count]   = total_count
  super
end
run(event = nil) click to toggle source
Calls superclass method Dynflow::Action::Cancellable#run
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 14
def run(event = nil)
  if event === PlanNextBatch
    spawn_plans if can_spawn_next_batch?
    suspend
  else
    super
  end
end
run_progress() click to toggle source

The same logic as in Action::WithSubPlans, but calculated using the expected total count

# File lib/dynflow/action/with_bulk_sub_plans.rb, line 51
def run_progress
  if counts_set?
    (output[:success_count] + output[:failed_count]).to_f / total_count
  else
    0.1
  end
end
spawn_plans() click to toggle source
Calls superclass method
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 59
def spawn_plans
  super
ensure
  suspended_action << PlanNextBatch
end
total_count() click to toggle source

Should return the expected total count of tasks

# File lib/dynflow/action/with_bulk_sub_plans.rb, line 35
def total_count
  raise NotImplementedError
end

Private Instance Methods

can_spawn_next_batch?() click to toggle source
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 83
def can_spawn_next_batch?
  total_count - output[:success_count] - output[:pending_count] - output[:failed_count] > 0
end