Sha256: 82e50bc0cd90643283cb2ec5c23c0af7327408bc1b85ce2ca8a10a5d57ac7f53

Contents?: true

Size: 1 KB

Versions: 14

Compression:

Stored size: 1 KB

Contents

require "active_job"

module CanvasSync
  # Inherit from this class to build a Job that will log to the canvas_sync_job_logs table
  class Job < ActiveJob::Base
    around_perform do |job, block|
      @job_log = CanvasSync::JobLog.create(
        started_at: Time.now,
        job_class: self.class.name,
        job_arguments: job.arguments,
      )

      begin
        block.call
      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 @job_log.job_class == "CanvasSync::Jobs::ReportChecker" && @job_log.status != JobLog::ERROR_STATUS
          @job_log.destroy
        else
          @job_log.completed_at = Time.now
          @job_log.status ||= JobLog::SUCCESS_STATUS
          @job_log.save!
        end
      end
    end

    def report_checker_wait_time
      Rails.env.development? ? 1.second : 30.seconds
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
canvas_sync-0.5.1 lib/canvas_sync/job.rb
canvas_sync-0.4.1 lib/canvas_sync/job.rb
canvas_sync-0.4.0 lib/canvas_sync/job.rb
canvas_sync-0.3.23 lib/canvas_sync/job.rb
canvas_sync-0.3.22 lib/canvas_sync/job.rb
canvas_sync-0.3.21 lib/canvas_sync/job.rb
canvas_sync-0.3.20 lib/canvas_sync/job.rb
canvas_sync-0.3.19 lib/canvas_sync/job.rb
canvas_sync-0.3.18 lib/canvas_sync/job.rb
canvas_sync-0.3.17 lib/canvas_sync/job.rb
canvas_sync-0.3.16 lib/canvas_sync/job.rb
canvas_sync-0.3.15 lib/canvas_sync/job.rb
canvas_sync-0.3.14 lib/canvas_sync/job.rb
canvas_sync-0.3.13 lib/canvas_sync/job.rb