Skip to content

Instantly share code, notes, and snippets.

@gabrieljoelc
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrieljoelc/11386605 to your computer and use it in GitHub Desktop.
Save gabrieljoelc/11386605 to your computer and use it in GitHub Desktop.
Sneakers gem handler error and timeout pseudo code
# if message doesn't contain max retry info then
# publish to delay (dead-letter) queue with first step
# elsif message contains retry info that's not max then
# update retry step and publish to delay dead-letter queue
# else
# send to error (dead-letter) queue
# ripped off code from https://github.com/ooyala/retries/blob/master/lib/retries.rb
# at this point, I don't think this will work with dead-letter queues because you can't change the TTL on-the-fly (it's
# a per queue setting)
def get_delay_seconds()
if @sleep_enabled
# The sleep time is an exponentially-increasing function of base_delay_seconds. But, it never exceeds
# max_delay_seconds.
delay_seconds = [@base_delay_seconds * (2 ** (attempts - 1)), @max_delay_seconds].min
# Randomize to a random value in the range delay_seconds/2 .. delay_seconds
delay_seconds = delay_seconds * (0.5 * (1 + rand()))
# But never sleep less than base_delay_seconds
delay_seconds = [@base_delay_seconds, delay_seconds].max
# convert to milliseconds
delay_seconds * 1000
end
0.0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment