Sha256: ef2596dc9b6c588c4c9306202cc808b49e5c4f53da965fa13b21c1b9c97a6681

Contents?: true

Size: 782 Bytes

Versions: 9

Compression:

Stored size: 782 Bytes

Contents

module BarbequeClient
  class ExponentialRetry
    MAX_DELAY_SECONDS = (ENV['BARBEQUE_MAX_RETRY_DELAY'] || 900).to_i

    # https://github.com/mperham/sidekiq/blob/v4.1.2/lib/sidekiq/middleware/server/retry_jobs.rb#L176-L179
    # @return [Integer] seconds
    def self.exponential_backoff(count)
      (count ** 4) + 15 + (rand(30) * (count + 1))
    end

    # @param [Integer] count - Count of retry
    def initialize(count)
      @count = count
    end

    # @param [String] message_id
    def retry(message_id)
      BarbequeClient.client.retry_execution(
        message_id:    message_id,
        delay_seconds: [delay_seconds, MAX_DELAY_SECONDS].min,
      )
    end

    private

    def delay_seconds
      ExponentialRetry.exponential_backoff(@count)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
barbeque_client-0.11.0 lib/barbeque_client/exponential_retry.rb
barbeque_client-0.10.2 lib/barbeque_client/exponential_retry.rb
barbeque_client-0.10.1 lib/barbeque_client/exponential_retry.rb
barbeque_client-0.10.0 lib/barbeque_client/exponential_retry.rb
barbeque_client-0.9.1 lib/barbeque_client/exponential_retry.rb
barbeque_client-0.9.0 lib/barbeque_client/exponential_retry.rb
barbeque_client-0.8.2 lib/barbeque_client/exponential_retry.rb
barbeque_client-0.8.1 lib/barbeque_client/exponential_retry.rb
barbeque_client-0.8.0 lib/barbeque_client/exponential_retry.rb