Class: Webhookdb::Async::JobLogger

Inherits:
Appydays::Loggable::SidekiqJobLogger
  • Object
show all
Defined in:
lib/webhookdb/async/job_logger.rb

Class Method Summary collapse

Class Method Details

._ts(k, v) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/webhookdb/async/job_logger.rb', line 38

def self._ts(k, v)
  return nil if v.nil?
  return v unless k.end_with?("_at")
  return Time.at(v) if v.is_a?(Numeric)
  return Time.parse(v) if v.is_a?(String)
  return v
end

.durable_job_failure_notifier(job) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/webhookdb/async/job_logger.rb', line 10

def self.durable_job_failure_notifier(job)
  # See https://github.com/sidekiq/sidekiq/wiki/Job-Format#activejob-middleware-format
  # for job format.
  job = job.dup
  # These fields always exist.
  jargs = job.delete("args")
  jcls = job.delete("class")
  jid = job.delete("jid")
  jq = job.delete("queue")
  jcreated = job.delete("created_at")
  safe_fields = [
    {title: "Job ID", value: jid, short: true},
    {title: "Job Class", value: "`#{jcls}`", short: true},
    {title: "Args", value: "```#{jargs.to_json}```"},
    {title: "Queue", value: jq, short: true},
    {title: "Created At", value: self._ts("created_at", jcreated), short: true},
  ]
  # The remaining fields can be added dynamically.
  other_fields = job.compact.
    map { |k, v| {title: k.humanize, value: self._ts(k, v), short: true} }
  Webhookdb::DeveloperAlert.new(
    subsystem: "Job Died",
    emoji: ":zombie:",
    fallback: "Job #{jcls}[#{jid}][#{jargs}] moved to DeadSet",
    fields: safe_fields + other_fields,
  ).emit
end