Sha256: f9f9cd9e95435f65305f4874b6bec3deb1fa7b93816a44e1afa580ee4028710b

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

module Sqewer
  module Contrib
    # Can be used as a wrapper middleware in an ExecutionContext to log exceptions
    # to Appsignal and to monitor performance. Will only activate
    # if the Appsignal gem is loaded within the current process and active.
    class AppsignalWrapper
      # Unserialize the job
      def around_deserialization(serializer, msg_id, msg_payload)
        return yield unless (defined?(Appsignal) && Appsignal.active?)

        Appsignal.monitor_transaction('perform_job.demarshal', 
          :class => serializer.class.to_s, :params => {:recepit_handle => msg_id}, :method => 'deserialize') do
          yield
        end
      end

      # Run the job with Appsignal monitoring.
      def around_execution(job, context)
        return yield unless (defined?(Appsignal) && Appsignal.active?)
        job_params = job.respond_to?(:to_h) ? job.to_h : {}
        Appsignal.monitor_transaction('perform_job.sqewer', 
          :class => job.class.to_s, :params => job_params, :method => 'run') do |t|
            context['appsignal.transaction'] = t
          yield
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sqewer-5.0.2 lib/sqewer/extensions/appsignal_wrapper.rb
sqewer-5.0.1 lib/sqewer/extensions/appsignal_wrapper.rb