Sha256: 7dd631bce6328e7716947680b73e61b3d8765e67ba1aac547fdc0caeb559e6ac

Contents?: true

Size: 1.43 KB

Versions: 6

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module PlainApm
  module Hooks
    class ActiveJob < ActiveSupportSubscriber
      NOTIFICATION_PATTERN = /\A[^!]\w+\.active_job\Z/.freeze

      private

      def notification_pattern
        NOTIFICATION_PATTERN
      end

      def payload(event)
        name, source = *event.name.split(".")
        payload = event.payload
        job = payload[:job]

        base = {
          "source" => source,
          "name" => name,
          "backtrace" => filtered_backtrace,
          "started_at" => event.time,
          "finished_at" => event.end,
          "allocations" => event.allocations,
          "thread_allocations" => event.thread_allocations,
          "queue_name" => job.queue_name,
          "job_id" => job.job_id,
          "job_class" => job.class.name,
          "job_arguments" => job.arguments,
          "executions" => job.executions,
          "scheduled_at" => job.scheduled_at,
          "adapter" => payload[:adapter].class.name,
          "aborted" => payload[:aborted]
        }

        case name
        when "enqueue", "enqueue_at", "perform"
          base
        when "enqueue_retry"
          base.merge({
            "error" => payload[:error],
            "wait" => payload[:wait]
          })
        when "retry_stopped", "discard"
          base.merge({
            "error" => payload[:error]
          })
        when "perform_start"
          nil
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
plain_apm-0.5.5 lib/plain_apm/hooks/active_job.rb
plain_apm-0.5.4 lib/plain_apm/hooks/active_job.rb
plain_apm-0.5.3 lib/plain_apm/hooks/active_job.rb
plain_apm-0.5.2 lib/plain_apm/hooks/active_job.rb
plain_apm-0.5.1 lib/plain_apm/hooks/active_job.rb
plain_apm-0.5.0 lib/plain_apm/hooks/active_job.rb