Sha256: ad21c1c8c70a7681e18e7e39e6f1e04ec721f18590410bd79146673a5edf14f2

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module Airbrake
  module Rails
    # Enables support for exceptions occurring in ActiveJob jobs.
    module ActiveJob
      extend ActiveSupport::Concern

      # @return [Array<Regexp>] the list of known adapters
      ADAPTERS = [/Resque/, /Sidekiq/, /DelayedJob/].freeze

      def self.notify_airbrake(exception, job)
        queue_adapter = job.class.queue_adapter.to_s

        # Do not notify twice if a queue_adapter is configured already.
        raise exception if ADAPTERS.any? { |a| a =~ queue_adapter }

        notice = Airbrake.build_notice(exception)
        notice[:context][:component] = 'active_job'
        notice[:context][:action] = job.class.name
        notice[:params].merge!(job.serialize)

        Airbrake.notify(notice)

        raise exception
      end

      def self.perform(job, block)
        timing = Airbrake::Benchmark.measure do
          block.call
        end
      rescue StandardError => exception
        Airbrake.notify_queue_sync(
          queue: job.class.name,
          error_count: 1,
          timing: 0.01,
        )
        raise exception
      else
        Airbrake.notify_queue_sync(
          queue: job.class.name,
          error_count: 0,
          timing: timing,
        )
      end

      included do
        rescue_from(Exception) do |exception|
          Airbrake::Rails::ActiveJob.notify_airbrake(exception, self)
        end

        around_perform do |job, block|
          Airbrake::Rails::ActiveJob.perform(job, block)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
airbrake-10.0.1 lib/airbrake/rails/active_job.rb