Class: Spree::MaintenanceTasks::RunJob
- Includes:
- ActiveJob::Continuable
- Defined in:
- app/jobs/spree/maintenance_tasks/run_job.rb
Overview
Executes one Spree::MaintenanceTaskRun on Active Job Continuations (docs/plans/6.0-maintenance-tasks.md).
Three things can stop a run mid-collection, and all three resolve to the same checkpoint: the worker is shutting down (Continuations re-queue the job), the execution has used its time slice (the runner re-queues itself so no single task holds a worker), or an operator asked to cancel (the Cancel service writes the request, the runner observes it here). The run row's cursor is written before each checkpoint, so whichever path fires, the next execution restarts from the same record.
Constant Summary
Constants inherited from BaseJob
Instance Method Summary collapse
-
#perform(run_id, inline: false) ⇒ Object
A run that fails is recorded as failed; it must not be replayed by the backend behind the operator's back.
Instance Method Details
#perform(run_id, inline: false) ⇒ Object
A run that fails is recorded as failed; it must not be replayed by the backend behind the operator's back. Running it again is an explicit action.
inline is a run executing in the caller's own process — the
upgrade walk and the command line. It holds no worker, so it is not
sliced: handing the remainder to a worker would let the caller report
a step done that has not finished, on a deploy where no worker runs.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/jobs/spree/maintenance_tasks/run_job.rb', line 26 def perform(run_id, inline: false) # Outside the steps on purpose — runs on every execution, resumes # included. @run = Spree::MaintenanceTaskRun.find_by(id: run_id) return if @run.nil? # `cancelling` counts as active: a job re-queued after its worker # stopped is the only execution that will ever answer it. return unless @run.active? @task_class = @run.task_class return unfindable_task if @task_class.nil? @inline = inline @execution_started_at = Time.current @time_running_before = @run.time_running.to_f prepare return if @halted check_operator_request return if @halted return refuse_duplicate if duplicate_run? step :start # Seeded from the row rather than from the continuation: the row # survives a dropped job, which a re-queued execution then picks up # with no continuation at all. step :process_collection, start: @run.cursor step :finish rescue SignalException => e # Ctrl-C or a deploy stopping an inline run. No job was queued for it, # so nothing would ever come back to a run left `running`, and it # would block every later run of its task. record_error(e) if @inline && run&.reload&.active? raise end |