Sha256: 551433191e64eb39b60408e4a3c8ca4258754871ab61500cdda498c17a4fa867

Contents?: true

Size: 1.76 KB

Versions: 8

Compression:

Stored size: 1.76 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,
          "enqueued_at" => enqueued_at(job),
          "dequeued_at" => dequeued_at(job),
          "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

      private

      def enqueued_at(job)
        Time.parse(job.enqueued_at).to_f if job.enqueued_at
      end

      def dequeued_at(job)
        Time.parse(job.dequeued_at).to_f if job.respond_to?(:dequeued_at) && job.dequeued_at
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
plain_apm-0.6.6 lib/plain_apm/hooks/active_job.rb
plain_apm-0.6.5 lib/plain_apm/hooks/active_job.rb
plain_apm-0.6.4 lib/plain_apm/hooks/active_job.rb
plain_apm-0.6.3 lib/plain_apm/hooks/active_job.rb
plain_apm-0.6.2 lib/plain_apm/hooks/active_job.rb
plain_apm-0.6.1 lib/plain_apm/hooks/active_job.rb
plain_apm-0.5.7 lib/plain_apm/hooks/active_job.rb
plain_apm-0.5.6 lib/plain_apm/hooks/active_job.rb