Module: CanvasSync::JobBatches::ActiveJob

Defined in:
lib/canvas_sync/job_batches/active_job.rb

Defined Under Namespace

Modules: BatchAwareJob Classes: ActiveJobCallbackWorker

Class Method Summary collapse

Class Method Details

.configureObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/canvas_sync/job_batches/active_job.rb', line 89

def self.configure
  ::ActiveJob::Base.include BatchAwareJob

  begin
    ActiveSupport::Notifications.subscribe "discard.active_job" do |*args|
      handle_job_death(args)
    end

    ActiveSupport::Notifications.subscribe "retry_stopped.active_job" do |*args|
      handle_job_death(args)
    end
  rescue => err
    Rails.logger.warn(err)
  end

  Batch::Callback.worker_class ||= ActiveJobCallbackWorker
end

.handle_job_death(job, error = nil) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/canvas_sync/job_batches/active_job.rb', line 76

def self.handle_job_death(job, error = nil)
  if job.is_a?(Array)
    event = ActiveSupport::Notifications::Event.new(*job)
    payload = event.payload
    job = payload[:job].serialize
    error = payload[:error]
  end

  if job["job_id"].present? && job["batch_id"].present?
    CanvasSync::JobBatches::Batch.process_dead_job(job['batch_id'], job['job_id'])
  end
end