Class: SidekiqMeteredExceptions::MeteredRavenErrorHandler

Inherits:
Raven::SidekiqErrorHandler
  • Object
show all
Defined in:
lib/metered_raven_error_handler.rb

Instance Method Summary collapse

Instance Method Details

#call(ex, original_context) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/metered_raven_error_handler.rb', line 6

def call(ex, original_context)
  ::Rails.logger.debug("MeteredRavenErrorHandler -- Error on Sidekiq job. Exception: #{ex.inspect} - Context: #{original_context.inspect}")

  # symbolize keys so we don't have to worry about strings vs. symbols
  context = original_context.deep_symbolize_keys

  # If the job context has a `retry_count` key, it tells us how many times the job has been REtried so far.
  # If it lacks this key, it has never been retried; this is the first attempt.
  retry_count = (context[:retry_count] || (context[:job] && context[:job][:retry_count])).try(:to_i) || 0

  # Is this a retryable job?
  is_retryable = context[:retry] || (context[:job] && context[:job][:retry])

  # We notify if this job has been retried at least once.
  # Someday we plan to make this number configurable.
  # If this isn't a retryable job, we notify even if this is the first attempt, because there will not be more attempts.
  if retry_count > 0 || !is_retryable
    ::Rails.logger.debug("MeteredRavenErrorHandler -- Current retry count: #{retry_count}. Notifying upstream...")

    super(ex, original_context)
  end
end