No commit activity in last 3 years
No release in over 3 years
Retries in specified time interval. Supports `on_retry` and `on_error` callbacks
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.2
~> 0.12
~> 3.9
~> 2.11
 Project Readme

SneakersRetryHandler

Run your worker with delayed retrying. Define on_retry and on_error callbacks.

Install

gem install sneakers_retry_handler

Usage of the DelayedRetry

The DelayedRetry handler is an extension of the default MaxRetry handler. It will try to process the message specified number of times. When the maximum number of retries is reached it will put the message on an error queue.

When defining your worker, you have to define these extra arguments:

  • number_of_retries: Specifies how many times to retry.

  • sleep_before_retry: Retrying delay.

  • retriable_errors: The list of errors. Puts the message on an error queue otherwise.

  • x-dead-letter-exchange: The name of the dead-letter exchange where failed messages will be published to.

  • on_retry and on_error: Callbacks.

Here's an example:

class BusyWorker
  include Sneakers::Worker

  from_queue(
    'busy_worker_queue',
+   exchange: 'retry_exchange',
+   exchange_type: :topic,
+   handler: Sneakers::Handlers::DelayedRetry,
+   arguments: {
+     'x-dead-letter-exchange': 'retry_exchange'
+   },
+   number_of_retries: 3,
+   sleep_before_retry: 2,
+   retriable_errors: [Faraday::TimeoutError],
+   on_retry: proc do |error, payload, tries|
+     /* put your logic here */
+   end,
+   on_error: proc do |error, payload, tries|
+     /* put your logic here */
+   end
  )

  def work(*args)
    ack!
  end
end