Module: Workers::StatusBroadcastable::PerformWrapper
- Included in:
- Workers::StatusBroadcastable
- Defined in:
- app/concerns/workers/status_broadcastable.rb
Overview
Module to wrap perform method and broadcast on completion
Instance Method Summary collapse
-
#perform(*args) ⇒ Object
Runs the job, then schedules a terminal broadcast on a background thread.
Instance Method Details
#perform(*args) ⇒ Object
Runs the job, then schedules a terminal broadcast on a background thread.
Sidekiq::Status updates happen AFTER perform fully returns, so the
terminal broadcast is delayed until after our code exits.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/concerns/workers/status_broadcastable.rb', line 96 def perform(*args) super ensure # Spawn a thread to broadcast after Sidekiq has updated the status # Sidekiq::Status updates happen AFTER perform fully returns, # so we need to delay the broadcast until after our code exits job_id = jid Thread.new do sleep 1 # Wait for Sidekiq to update status broadcast_job_status(terminal: true) rescue StandardError => e Rails.logger.warn "[StatusBroadcastable] Delayed broadcast failed for #{job_id}: #{e.}" end end |