Sha256: 5643f5723d77fedeabc6c24a28eb5211d9ad0061a1fe0bd809a8cbd194bc9d9b

Contents?: true

Size: 898 Bytes

Versions: 161

Compression:

Stored size: 898 Bytes

Contents

module CanvasSync
  module Sidekiq
    class Middleware
      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
    end
  end
end

Version data entries

161 entries across 161 versions & 1 rubygems

Version Path
canvas_sync-0.6.0 lib/canvas_sync/sidekiq_job.rb