Class: Appydays::Loggable::SidekiqJobLogger

Inherits:
Sidekiq::JobLogger
  • Object
show all
Includes:
Configurable, Appydays::Loggable
Defined in:
lib/appydays/loggable/sidekiq_job_logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Appydays::Loggable

[], configure_12factor, default_level=, ensure_stderr_appender, included, set_default_level, with_log_tags

Methods included from Configurable

included

Class Method Details

.death_handler(job, ex) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/appydays/loggable/sidekiq_job_logger.rb', line 101

def self.death_handler(job, ex)
  self.logger.error(
    "job_retries_exhausted",
    {
      job_class: job["class"],
      job_args: job["args"],
      job_retry: job["retry"],
      job_queue: job["queue"],
      job_dead: job["dead"],
      job_id: job["jid"],
      job_created_at: job["created_at"],
      job_enqueued_at: job["enqueued_at"],
      job_error_message: job["error_message"],
      job_error_class: job["error_class"],
      job_failed_at: job["failed_at"],
      job_retry_count: job["retry_count"],
    },
    ex,
  )
end

.error_handler(ex, ctx) ⇒ Object



61
62
63
64
65
66
67
68
69
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
96
97
98
99
# File 'lib/appydays/loggable/sidekiq_job_logger.rb', line 61

def self.error_handler(ex, ctx)
  # ctx looks like:
  # {
  # :context=>"Job raised exception",
  # :job=>
  #  {"class"=>"App::Async::FailingJobTester",
  #   "args"=>
  #    [{"id"=>"e8e03571-9851-4daa-a801-a0b43282f317",
  #      "name"=>"app.test_failing_job",
  #      "payload"=>[true]}],
  #   "retry"=>true,
  #   "queue"=>"default",
  #   "jid"=>"cb00c4fe9b2f16b72797d35c",
  #   "created_at"=>1567811837.798969,
  #   "enqueued_at"=>1567811837.79901},
  # :jobstr=>
  #  "{\"class\":\"App::Async::FailingJobTester\", <etc>"
  # }
  job = ctx[:job]
  # If there was a connection error, you may end up with no job context.
  # It's very difficult to test this usefully, so it's not tested.
  unless job
    self.logger.error("job_error_no_job", {}, ex)
    return
  end
  self.logger.error(
    "job_error",
    {
      job_class: job["class"],
      job_args: job["args"],
      job_retry: job["retry"],
      job_queue: job["queue"],
      job_id: job["jid"],
      job_created_at: job["created_at"],
      job_enqueued_at: job["enqueued_at"],
    },
    ex,
  )
end

Instance Method Details

#call(item, _queue, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/appydays/loggable/sidekiq_job_logger.rb', line 23

def call(item, _queue, &block)
  start = self.now
  tags = {
    job_class: item["class"],
    job_id: item["jid"],
    thread_id: self.tid,
  }
  self.with_log_tags(tags) do
    self.call_inner(start, &block)
  end
end