Class: SneakersHandlers::ExponentialBackoffHandler
- Inherits:
-
Object
- Object
- SneakersHandlers::ExponentialBackoffHandler
- Defined in:
- lib/sneakers_handlers/exponential_backoff_handler.rb
Constant Summary collapse
- DEFAULT_MAX_RETRY_ATTEMPTS =
25
- DEFAULT_BACKOFF_FUNCTION =
-> (attempt_number) { (attempt_number + 1) ** 2 }
Instance Attribute Summary collapse
-
#backoff_function ⇒ Object
readonly
Returns the value of attribute backoff_function.
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#max_retries ⇒ Object
readonly
Returns the value of attribute max_retries.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
- #acknowledge(delivery_info, _, _) ⇒ Object
- #error(delivery_info, properties, message, err) ⇒ Object
-
#initialize(channel, queue, options) ⇒ ExponentialBackoffHandler
constructor
A new instance of ExponentialBackoffHandler.
- #noop(_delivery_info, _properties, _message) ⇒ Object
- #reject(delivery_info, properties, message, _requeue = true) ⇒ Object
- #timeout(delivery_info, properties, message) ⇒ Object
Constructor Details
#initialize(channel, queue, options) ⇒ ExponentialBackoffHandler
Returns a new instance of ExponentialBackoffHandler.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sneakers_handlers/exponential_backoff_handler.rb', line 31 def initialize(channel, queue, ) @queue = queue @channel = channel @options = @max_retries = [:max_retries] || DEFAULT_MAX_RETRY_ATTEMPTS @backoff_function = [:backoff_function] || DEFAULT_BACKOFF_FUNCTION create_error_exchange! queue.bind(primary_exchange, routing_key: queue.name) end |
Instance Attribute Details
#backoff_function ⇒ Object (readonly)
Returns the value of attribute backoff_function.
26 27 28 |
# File 'lib/sneakers_handlers/exponential_backoff_handler.rb', line 26 def backoff_function @backoff_function end |
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
26 27 28 |
# File 'lib/sneakers_handlers/exponential_backoff_handler.rb', line 26 def channel @channel end |
#max_retries ⇒ Object (readonly)
Returns the value of attribute max_retries.
26 27 28 |
# File 'lib/sneakers_handlers/exponential_backoff_handler.rb', line 26 def max_retries @max_retries end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/sneakers_handlers/exponential_backoff_handler.rb', line 26 def @options end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
26 27 28 |
# File 'lib/sneakers_handlers/exponential_backoff_handler.rb', line 26 def queue @queue end |
Instance Method Details
#acknowledge(delivery_info, _, _) ⇒ Object
43 44 45 |
# File 'lib/sneakers_handlers/exponential_backoff_handler.rb', line 43 def acknowledge(delivery_info, _, _) channel.acknowledge(delivery_info.delivery_tag, false) end |
#error(delivery_info, properties, message, err) ⇒ Object
51 52 53 |
# File 'lib/sneakers_handlers/exponential_backoff_handler.rb', line 51 def error(delivery_info, properties, , err) (delivery_info, properties, , err.inspect) end |
#noop(_delivery_info, _properties, _message) ⇒ Object
59 60 |
# File 'lib/sneakers_handlers/exponential_backoff_handler.rb', line 59 def noop(_delivery_info, _properties, ) end |
#reject(delivery_info, properties, message, _requeue = true) ⇒ Object
47 48 49 |
# File 'lib/sneakers_handlers/exponential_backoff_handler.rb', line 47 def reject(delivery_info, properties, , _requeue = true) (delivery_info, properties, , :reject) end |
#timeout(delivery_info, properties, message) ⇒ Object
55 56 57 |
# File 'lib/sneakers_handlers/exponential_backoff_handler.rb', line 55 def timeout(delivery_info, properties, ) (delivery_info, properties, , :timeout) end |