Sha256: 1963f79952dc61db8a1f6ef428037e35bd8204ad134cee660f4319e2aceb8ba2
Contents?: true
Size: 1.25 KB
Versions: 87
Compression:
Stored size: 1.25 KB
Contents
require 'securerandom' module Actions module RecurringAction # When included sets the base action to use the RecurringLogic middleware and configures # #trigger_repeat to be called when appropriate to trigger the next repeat. def self.included(base) base.middleware.use Actions::Middleware::RecurringLogic base.execution_plan_hooks.use :trigger_repeat, :on => [:planned, :failure] end # Hook to be called when a repetition needs to be triggered. This either happens when the plan goes into planned state # or when it fails. def trigger_repeat(execution_plan) request_id = ::Logging.mdc['request'] ::Logging.mdc['request'] = SecureRandom.uuid if execution_plan.delay_record && recurring_logic_task_group args = execution_plan.delay_record.args logic = recurring_logic_task_group.recurring_logic task_start_at = [task.start_at, Time.zone.now].max logic.trigger_repeat_after(task_start_at, self.class, *args) end ensure ::Logging.mdc['request'] = request_id end private def recurring_logic_task_group @task_group ||= task.task_groups .find { |tg| tg.is_a? ::ForemanTasks::TaskGroups::RecurringLogicTaskGroup } end end end
Version data entries
87 entries across 87 versions & 1 rubygems