Class: Shoryuken::Middleware::Server::ExponentialBackoffRetry

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/shoryuken/middleware/server/exponential_backoff_retry.rb

Instance Method Summary collapse

Methods included from Util

#elapsed, #fire_event, #logger, #unparse_queues, #worker_name

Instance Method Details

#call(worker, _queue, sqs_msg, _body) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/shoryuken/middleware/server/exponential_backoff_retry.rb', line 7

def call(worker, _queue, sqs_msg, _body)
  return yield unless worker.class.exponential_backoff?

  if sqs_msg.is_a?(Array)
    logger.warn { "Exponential backoff isn't supported for batch workers" }
    return yield
  end

  started_at = Time.now
  yield
rescue => ex
  retry_intervals = worker.class.get_shoryuken_options['retry_intervals']

  if retry_intervals.nil? || !handle_failure(sqs_msg, started_at, retry_intervals)
    # Re-raise the exception if the job is not going to be exponential backoff retried.
    # This allows custom middleware (like exception notifiers) to be aware of the unhandled failure.
    raise
  end

  logger.warn { "Message #{sqs_msg.message_id} will attempt retry due to error: #{ex.message}" }
  # since we didn't raise, lets log the backtrace for debugging purposes.
  logger.debug { ex.backtrace.join("\n") } unless ex.backtrace.nil?
end