Class: Sentry::InstJobs::Plugin

Inherits:
Delayed::Plugin
  • Object
show all
Defined in:
lib/sentry/inst_jobs/plugin.rb

Constant Summary collapse

INST_JOBS_CONTEXT_KEY =

need to symbolize strings as keyword arguments in Ruby 2.4~2.6

:"Inst-Jobs"
OP_NAME =
"inst_jobs"

Class Method Summary collapse

Class Method Details

.capture_exception(exception, job) ⇒ Object



69
70
71
# File 'lib/sentry/inst_jobs/plugin.rb', line 69

def self.capture_exception(exception, job)
  Sentry::InstJobs.capture_exception(exception, hint: { background: false }) if report?(job)
end

.compute_job_class(payload_object) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/sentry/inst_jobs/plugin.rb', line 60

def self.compute_job_class(payload_object)
  if payload_object.is_a? Delayed::PerformableMethod
    klass = payload_object.object.is_a?(Class) ? payload_object.object.name : payload_object.object.class.name
    "#{klass}##{payload_object.method}"
  else
    payload_object.class.name
  end
end

.finish_transaction(transaction, status) ⇒ Object



81
82
83
84
85
86
# File 'lib/sentry/inst_jobs/plugin.rb', line 81

def self.finish_transaction(transaction, status)
  return unless transaction

  transaction.set_http_status(status)
  transaction.finish
end

.generate_contexts(job) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/sentry/inst_jobs/plugin.rb', line 37

def self.generate_contexts(job)
  context = {}

  context[INST_JOBS_CONTEXT_KEY] = {
    id: job.id.to_s,
    priority: job.priority,
    attempts: job.attempts,
    run_at: job.run_at,
    locked_at: job.locked_at,
    locked_by: job.locked_by,
    queue: job.queue,
    created_at: job.created_at,
    last_error: job.last_error&.byteslice(0..1000),
    handler: job.handler&.byteslice(0..1000),
    job_class: compute_job_class(job.payload_object),
    tag: job.tag,
    strand: job.strand,
    singleton: job.singleton,
  }

  context
end

.report?(job) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
79
# File 'lib/sentry/inst_jobs/plugin.rb', line 73

def self.report?(job)
  return true unless Sentry.configuration.inst_jobs.report_after_job_retries

  # We use the predecessor because the job's attempts haven't been increased to the new
  # count at this point.
  job.attempts >= job.max_attempts.pred
end