Class: Barbeque::RetryConfig

Inherits:
ApplicationRecord show all
Defined in:
app/models/barbeque/retry_config.rb

Instance Method Summary collapse

Instance Method Details

#delay_seconds(retries) ⇒ Object

This algorithm is based on “Exponential Backoff And Jitter” article aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/



14
15
16
17
18
19
20
21
22
23
# File 'app/models/barbeque/retry_config.rb', line 14

def delay_seconds(retries)
  delay = 2 ** retries * base_delay
  if max_delay
    delay = [delay, max_delay].min
  end
  if jitter
    delay = Kernel.rand(0 .. delay)
  end
  delay
end

#should_retry?(retries) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'app/models/barbeque/retry_config.rb', line 8

def should_retry?(retries)
  retries < retry_limit
end