Sha256: eae552c27a74d9a76734df71a79f5be3fe9abc09fe8389f011ae1b6ba4cde733

Contents?: true

Size: 1.03 KB

Versions: 7

Compression:

Stored size: 1.03 KB

Contents

module Appsignal
  class Hooks
    # @api private
    class RakeHook < Appsignal::Hooks::Hook
      register :rake

      def dependencies_present?
        defined?(::Rake::Task)
      end

      def install
        ::Rake::Task.class_eval do
          alias :execute_without_appsignal :execute

          def execute(*args)
            execute_without_appsignal(*args)
          rescue => error
            # Format given arguments and cast to hash if possible
            params, _ = args
            params = params.to_hash if params.respond_to?(:to_hash)

            transaction = Appsignal::Transaction.create(
              SecureRandom.uuid,
              Appsignal::Transaction::BACKGROUND_JOB,
              Appsignal::Transaction::GenericRequest.new(
                :params => params
              )
            )
            transaction.set_action(name)
            transaction.set_error(error)
            transaction.complete
            Appsignal.stop("rake")
            raise error
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
appsignal-2.3.7 lib/appsignal/hooks/rake.rb
appsignal-2.3.6 lib/appsignal/hooks/rake.rb
appsignal-2.3.6.beta.1 lib/appsignal/hooks/rake.rb
appsignal-2.3.4 lib/appsignal/hooks/rake.rb
appsignal-2.3.3 lib/appsignal/hooks/rake.rb
appsignal-2.3.3.beta.1 lib/appsignal/hooks/rake.rb
appsignal-2.3.2 lib/appsignal/hooks/rake.rb