Class: CanvasSync::Sidekiq::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/canvas_sync/sidekiq_job.rb

Instance Method Summary collapse

Instance Method Details

#call(worker, job, _queue) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/canvas_sync/sidekiq_job.rb', line 4

def call(worker, job, _queue)
  job_log = CanvasSync::JobLog.create(
    job_class: worker.class.to_s,
    job_arguments: job["args"],
    job_id: job["jid"],
    status: JobLog::RUNNING_STATUS,
    started_at: Time.now,
  )

  yield
  job_log.status = JobLog::SUCCESS_STATUS
rescue => e # rubocop:disable Style/RescueStandardError
  job_log.exception = "#{e.class}: #{e.message}"
  job_log.backtrace = e.backtrace
  job_log.status = JobLog::ERROR_STATUS
  raise e
ensure
  if CanvasSync.config.classes_to_only_log_errors_on.include?(job_log.job_class) && job_log.status != JobLog::ERROR_STATUS
    job_log.destroy
  else
    job_log.completed_at = Time.now
    job_log.save!
  end
end