module NewRelic::Agent::Instrumentation::DelayedJob::Naming
Constants
- CLASS_METHOD_DELIMITER
- INSTANCE_METHOD_DELIMITER
- LEGACY_DJ_DEFAULT_CLASS
- LEGACY_DJ_FORMAT_DELIMITER
- LEGACY_DJ_FORMAT_PREFIX
Public Instance Methods
class_name_from_legacy_performable_method(payload_object)
click to toggle source
If parsing for the class name fails, return a sensible default
# File lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb, line 41 def class_name_from_legacy_performable_method(payload_object) payload_object.object.split(LEGACY_DJ_FORMAT_DELIMITER)[1] || LEGACY_DJ_DEFAULT_CLASS end
delimiter(payload_object)
click to toggle source
# File lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb, line 55 def delimiter(payload_object) if payload_object.object.is_a?(Class) CLASS_METHOD_DELIMITER else INSTANCE_METHOD_DELIMITER end end
legacy_performable_method?(payload_object)
click to toggle source
Older versions of Delayed Job use a semicolon-delimited string to stash the class name. The format of this string is “LOAD;<class name>;<ORM ID>”
# File lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb, line 36 def legacy_performable_method?(payload_object) payload_object.object.is_a?(String) && payload_object.object.start_with?(LEGACY_DJ_FORMAT_PREFIX) end
method_name(payload_object)
click to toggle source
DelayedJob’s interface for the async method’s name varies across the gem’s versions
# File lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb, line 64 def method_name(payload_object) if payload_object.respond_to?(:method_name) payload_object.method_name else # early versions of Delayed Job override Object#method with the method name payload_object.method end end
name_from_payload(payload_object)
click to toggle source
# File lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb, line 23 def name_from_payload(payload_object) if payload_object.is_a?(::Delayed::PerformableMethod) # payload_object contains a reference to an object # that received an asynchronous method call via .delay or .handle_asynchronously "#{object_name(payload_object)}#{delimiter(payload_object)}#{method_name(payload_object)}" else # payload_object is a user-defined job enqueued via Delayed::Job.enqueue payload_object.class.name end end
object_name(payload_object)
click to toggle source
# File lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb, line 45 def object_name(payload_object) if payload_object.object.is_a?(Class) payload_object.object.to_s elsif legacy_performable_method?(payload_object) class_name_from_legacy_performable_method(payload_object) else payload_object.object.class.name end end