Module: Hutch::Retry::Consumer::ClassMethods
- Includes:
- Logging
- Defined in:
- lib/hutch/retry/consumer.rb
Instance Method Summary collapse
- #channel ⇒ Object
- #create_retry_queue!(delay) ⇒ Object
- #create_retry_queues!(broker) ⇒ Object
- #exp_backoff(retry_count) ⇒ Object
- #get_max_retries ⇒ Object
- #get_retry_on ⇒ Object
- #max_retries(counter) ⇒ Object
- #retry_exchange ⇒ Object
- #retry_exchange_durable? ⇒ Boolean (also: #retry_query_durable?)
- #retry_exchange_name ⇒ Object
- #retry_exchange_options(options = {}) ⇒ Object
- #retry_on(array) ⇒ Object
Instance Method Details
#channel ⇒ Object
42 43 44 |
# File 'lib/hutch/retry/consumer.rb', line 42 def channel @broker.channel end |
#create_retry_queue!(delay) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/hutch/retry/consumer.rb', line 65 def create_retry_queue!(delay) channel.queue( "#{retry_exchange_name}.#{delay}", durable: retry_query_durable?, arguments: { "x-dead-letter-exchange": @broker.exchange.name, "x-message-ttl": delay * 1_000 } ).bind(retry_exchange, arguments: { "backoff-delay": delay, "x-match": "all" }) end |
#create_retry_queues!(broker) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/hutch/retry/consumer.rb', line 55 def create_retry_queues!(broker) logger.info "setting up retry queues for #{retry_exchange_name} exchange" @broker = broker (0...get_max_retries) .map(&method(:exp_backoff)) .each(&method(:create_retry_queue!)) end |
#exp_backoff(retry_count) ⇒ Object
25 26 27 |
# File 'lib/hutch/retry/consumer.rb', line 25 def exp_backoff(retry_count) ((retry_count + 1)**4) + 30 + (retry_count + 2) end |
#get_max_retries ⇒ Object
17 18 19 |
# File 'lib/hutch/retry/consumer.rb', line 17 def get_max_retries @max_retries || 5 end |
#get_retry_on ⇒ Object
21 22 23 |
# File 'lib/hutch/retry/consumer.rb', line 21 def get_retry_on @retry_on || [StandardError] end |
#max_retries(counter) ⇒ Object
9 10 11 |
# File 'lib/hutch/retry/consumer.rb', line 9 def max_retries(counter) @max_retries = counter end |
#retry_exchange ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/hutch/retry/consumer.rb', line 46 def retry_exchange @retry_exchange ||= Hutch::Adapter.new_exchange( channel, "headers", retry_exchange_name, durable: retry_exchange_durable? ) end |
#retry_exchange_durable? ⇒ Boolean Also known as: retry_query_durable?
37 38 39 |
# File 'lib/hutch/retry/consumer.rb', line 37 def retry_exchange_durable? (@retry_exchange_options || {}).fetch(:durable, true) end |
#retry_exchange_name ⇒ Object
33 34 35 |
# File 'lib/hutch/retry/consumer.rb', line 33 def retry_exchange_name (@retry_exchange_options || {}).fetch(:name, "#{get_queue_name}.retry") end |
#retry_exchange_options(options = {}) ⇒ Object
29 30 31 |
# File 'lib/hutch/retry/consumer.rb', line 29 def ( = {}) @retry_exchange_options = end |
#retry_on(array) ⇒ Object
13 14 15 |
# File 'lib/hutch/retry/consumer.rb', line 13 def retry_on(array) @retry_on = array end |