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
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 55 def batch_size DEFAULT_BATCH_SIZE end
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 75 def cancel!(force = false) # Count the not-yet-planned tasks as cancelled output[:cancelled_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 # Pass the cancel event to running sub plans if they can be cancelled sub_plans(:state => 'running').each { |sub_plan| sub_plan.cancel(force) if sub_plan.cancellable? } suspend end
Returns the items in the current batch
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 49 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
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 38 def increase_counts(planned, failed) super(planned, failed, false) output[:planned_count] += planned end
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 31 def initiate output[:planned_count] = 0 output[:cancelled_count] = 0 output[:total_count] = total_count super end
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 27 def on_planning_finished suspend end
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 14 def run(event = nil) if event === PlanNextBatch if can_spawn_next_batch? spawn_plans suspend else on_planning_finished end else super end end
The same logic as in Action::WithSubPlans, but calculated using the expected total count
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 60 def run_progress if counts_set? && total_count > 0 sum = output.values_at(:success_count, :cancelled_count, :failed_count).reduce(:+) sum.to_f / total_count else 0.1 end end
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 69 def spawn_plans super ensure suspended_action << PlanNextBatch end
Should return the expected total count of tasks
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 44 def total_count raise NotImplementedError end
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 96 def can_spawn_next_batch? remaining_count > 0 end
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 92 def done? !can_spawn_next_batch? && super end
# File lib/dynflow/action/with_bulk_sub_plans.rb, line 100 def remaining_count total_count - output[:cancelled_count] - output[:planned_count] end