Class: Atatus::Spies::DelayedJobSpy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/atatus/spies/delayed_job.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

CLASS_SEPARATOR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'.'
METHOD_SEPARATOR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'#'
TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'Delayed::Job'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.invoke_job(job, *args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/atatus/spies/delayed_job.rb', line 44

def self.invoke_job(job, *args, &block)
  job_name = name_from_payload(job.payload_object)
  transaction = Atatus.start_transaction(job_name, TYPE)
  job.invoke_job_without_apm(*args, &block)
  transaction.done 'success'
rescue ::Exception => e
  Atatus.report(e, handled: false)
  transaction.done 'error'
  raise
ensure
  Atatus.end_transaction
end

.name_from_payload(payload_object) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
60
61
62
63
# File 'lib/atatus/spies/delayed_job.rb', line 57

def self.name_from_payload(payload_object)
  if payload_object.is_a?(::Delayed::PerformableMethod)
    performable_method_name(payload_object)
  else
    payload_object.class.name
  end
end

.name_separator(payload_object) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



78
79
80
# File 'lib/atatus/spies/delayed_job.rb', line 78

def self.name_separator(payload_object)
  payload_object.object.is_a?(Class) ? CLASS_SEPARATOR : METHOD_SEPARATOR
end

.object_name(payload_object) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



72
73
74
75
76
# File 'lib/atatus/spies/delayed_job.rb', line 72

def self.object_name(payload_object)
  object = payload_object.object
  klass = object.is_a?(Class) ? object : object.class
  klass.name
end

.performable_method_name(payload_object) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
68
69
70
# File 'lib/atatus/spies/delayed_job.rb', line 65

def self.performable_method_name(payload_object)
  class_name = object_name(payload_object)
  separator = name_separator(payload_object)
  method_name = payload_object.method_name
  "#{class_name}#{separator}#{method_name}"
end

Instance Method Details

#installObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/atatus/spies/delayed_job.rb', line 29

def install
  if defined?(::Delayed) && defined?(::Delayed::Backend) && defined?(::Delayed::Backend::Base)

    ::Delayed::Backend::Base.class_eval do
      alias invoke_job_without_apm invoke_job

      def invoke_job(*args, &block)
        ::Atatus::Spies::DelayedJobSpy
          .invoke_job(self, *args, &block)
      end
    end

  end
end