Sha256: b7159246e4aa9cfbd827f93dfee89cbfac360de806f369048478f70551728f4f

Contents?: true

Size: 1.68 KB

Versions: 34

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

module Appsignal
  class Hooks
    # @api private
    class ResqueHook < Appsignal::Hooks::Hook
      register :resque

      def dependencies_present?
        defined?(::Resque)
      end

      def install
        Resque::Job.class_eval do
          alias_method :perform_without_appsignal, :perform

          def perform
            transaction = Appsignal::Transaction.create(
              SecureRandom.uuid,
              Appsignal::Transaction::BACKGROUND_JOB,
              Appsignal::Transaction::GenericRequest.new({})
            )

            Appsignal.instrument "perform.resque" do
              perform_without_appsignal
            end
          rescue Exception => exception # rubocop:disable Lint/RescueException
            transaction.set_error(exception)
            raise exception
          ensure
            if transaction
              transaction.set_action_if_nil("#{payload["class"]}#perform")
              args =
                Appsignal::Utils::HashSanitizer.sanitize(
                  ResqueHelpers.arguments(payload),
                  Appsignal.config[:filter_parameters]
                )
              transaction.params = args if args
              transaction.set_tags("queue" => queue)

              Appsignal::Transaction.complete_current!
            end
            Appsignal.stop("resque")
          end
        end
      end

      class ResqueHelpers
        def self.arguments(payload)
          case payload["class"]
          when "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper"
            nil # Set in the ActiveJob integration
          else
            payload["args"]
          end
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
appsignal-2.11.10-java lib/appsignal/hooks/resque.rb
appsignal-2.11.10 lib/appsignal/hooks/resque.rb
appsignal-2.11.9-java lib/appsignal/hooks/resque.rb
appsignal-2.11.9 lib/appsignal/hooks/resque.rb
appsignal-2.11.8-java lib/appsignal/hooks/resque.rb
appsignal-2.11.8 lib/appsignal/hooks/resque.rb
appsignal-2.11.7 lib/appsignal/hooks/resque.rb
appsignal-2.11.7-java lib/appsignal/hooks/resque.rb
appsignal-2.11.6 lib/appsignal/hooks/resque.rb
appsignal-2.11.6-java lib/appsignal/hooks/resque.rb
appsignal-2.11.5-java lib/appsignal/hooks/resque.rb
appsignal-2.11.5 lib/appsignal/hooks/resque.rb
appsignal-2.11.4-java lib/appsignal/hooks/resque.rb
appsignal-2.11.4 lib/appsignal/hooks/resque.rb
appsignal-2.11.3-java lib/appsignal/hooks/resque.rb
appsignal-2.11.3 lib/appsignal/hooks/resque.rb
appsignal-2.11.2-java lib/appsignal/hooks/resque.rb
appsignal-2.11.2 lib/appsignal/hooks/resque.rb
appsignal-2.11.1-java lib/appsignal/hooks/resque.rb
appsignal-2.11.1 lib/appsignal/hooks/resque.rb