Class: Spree::MaintenanceTaskRun
- Inherits:
-
Object
- Object
- Spree::MaintenanceTaskRun
- Includes:
- HasStatus
- Defined in:
- app/models/spree/maintenance_task_run.rb
Overview
One execution of a Spree::MaintenanceTask — the durable record of what was run, by whom, with which arguments, and how far it got (docs/plans/6.0-maintenance-tasks.md).
The row is both the checkpoint and the audit trail. Its cursor is the
authoritative resume point: Active Job serializes its own continuation
into the job data, but that copy is lost whenever the job is dropped by
the backend, so the runner writes both in the same checkpoint and always
seeds from this column.
Runs are installation-wide: an upgrade step converts every store's data, so a run belongs to no store.
Constant Summary collapse
- ACTIVE_STATUSES =
%w[enqueued running interrupted cancelling].freeze
- INITIATED_VIA =
%w[dashboard api cli].freeze
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#duration ⇒ Object
Seconds of work.
-
#task_api_type ⇒ String
The task's short name, as the API and the dashboard identify it.
-
#task_class ⇒ Class?
The registered task class, or nil when the task has been removed from the registry since the run was created.
Instance Method Details
#active? ⇒ Boolean
66 67 68 |
# File 'app/models/spree/maintenance_task_run.rb', line 66 def active? ACTIVE_STATUSES.include?(status) end |
#duration ⇒ Object
Seconds of work. Time since the last checkpoint counts only while a worker holds the run — a queued run is not working.
72 73 74 75 76 |
# File 'app/models/spree/maintenance_task_run.rb', line 72 def duration return time_running unless status.in?(%w[running cancelling]) && started_at.present? time_running + (Time.current - (updated_at || started_at)) end |
#task_api_type ⇒ String
The task's short name, as the API and the dashboard identify it.
62 63 64 |
# File 'app/models/spree/maintenance_task_run.rb', line 62 def task_api_type Spree::MaintenanceTask.api_type_for(task_name) end |
#task_class ⇒ Class?
Returns the registered task class, or nil when the task has been removed from the registry since the run was created.
55 56 57 |
# File 'app/models/spree/maintenance_task_run.rb', line 55 def task_class Spree::MaintenanceTask.find_registered(task_name) end |