Class: SpreeCmCommissioner::AsyncOperationJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- ApplicationJob
- SpreeCmCommissioner::AsyncOperationJob
- Defined in:
- app/jobs/spree_cm_commissioner/async_operation_job.rb
Overview
Runs any AsyncOperation subclass. Same shape as ExportJob: load the record, call the one method the subclass implements.
ApplicationJob, not ApplicationUniqueJob: unique :until_executed keys on the job arguments, and
those carry a per-record id, so uniqueness could never collide -- it would buy a Redis lock for
nothing. The in_progress? guard below is what actually makes a duplicate enqueue a no-op.
Instance Method Summary collapse
Methods included from ApplicationJobDecorator
handle_deserialization_error, prepended
Instance Method Details
#perform(options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/jobs/spree_cm_commissioner/async_operation_job.rb', line 11 def perform( = {}) operation = SpreeCmCommissioner::AsyncOperation.find_by(id: [:async_operation_id]) return if operation.blank? # Guard on `done` only, not on "not in progress". An exception below marks the operation failed and # re-raises so Sidekiq retries -- guarding on in_progress? would make every one of those retries # return here immediately, which is the opposite of retrying. Completed work is the thing that must # never run twice; a failed operation is exactly what a retry is for. return if operation.done? operation.process! rescue StandardError => e operation&.fail!(e.) raise # ApplicationJob logs it; Sidekiq retries; Sentry captures. end |