Last active
August 29, 2015 14:00
-
-
Save gabrieljoelc/11386605 to your computer and use it in GitHub Desktop.
Sneakers gem handler error and timeout pseudo code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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