Class: Appsignal::Hooks::DelayedJobPlugin Private
- Extended by:
- Helpers
- Defined in:
- lib/appsignal/integrations/delayed_job_plugin.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.
Class Method Summary collapse
- .class_and_method_name_from_object_or_hash(payload, default_name) ⇒ Object private
- .extract_value(object_or_hash, field, default_value = nil, convert_to_s = false) ⇒ Object private
- .invoke_with_instrumentation(job, block) ⇒ Object private
Methods included from Helpers
Class Method Details
.class_and_method_name_from_object_or_hash(payload, default_name) ⇒ 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.
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/appsignal/integrations/delayed_job_plugin.rb', line 56 def self.class_and_method_name_from_object_or_hash(payload, default_name) # Attempt to find appsignal_name override class_and_method_name = extract_value(payload, :appsignal_name, nil) return class_and_method_name.split("#") if class_and_method_name.is_a?(String) pound_split = default_name.split("#") return pound_split if pound_split.length == 2 dot_split = default_name.split(".") return default_name if dot_split.length == 2 "#{default_name}#perform" end |
.extract_value(object_or_hash, field, default_value = nil, convert_to_s = false) ⇒ 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.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/appsignal/integrations/delayed_job_plugin.rb', line 70 def self.extract_value(object_or_hash, field, default_value = nil, convert_to_s = false) value = nil # Attempt to read value from hash if object_or_hash.respond_to?(:[]) value = begin object_or_hash[field] rescue NameError nil end end # Attempt to read value from object if value.nil? && object_or_hash.respond_to?(field) value = object_or_hash.send(field) end # Set default value if nothing was found value = default_value if value.nil? if convert_to_s value.to_s else value end end |
.invoke_with_instrumentation(job, 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.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/appsignal/integrations/delayed_job_plugin.rb', line 19 def self.invoke_with_instrumentation(job, block) payload = job.payload_object if payload.respond_to? :job_data # ActiveJob job_data = payload.job_data args = job_data.fetch("arguments", {}) class_name = job_data["job_class"] method_name = "perform" else # Delayed Job args = extract_value(payload, :args, {}) class_name, method_name = class_and_method_name_from_object_or_hash(payload, job.name) end params = Appsignal::Utils::HashSanitizer.sanitize( args, Appsignal.config[:filter_parameters] ) Appsignal.monitor_transaction( "perform_job.delayed_job", :class => class_name, :method => method_name, :metadata => { :id => extract_value(job, :id, nil, true), :queue => extract_value(job, :queue), :priority => extract_value(job, :priority, 0), :attempts => extract_value(job, :attempts, 0) }, :params => params, :queue_start => extract_value(job, :run_at) ) do block.call(job) end end |