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

Instance Method Details

#perform(*args) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/concerns/workers/status_broadcastable.rb', line 78

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.message}"
  end
end