Created
June 27, 2018 08:18
-
-
Save rkravchik/6b5f327d29e4431bf69b5008b2b40947 to your computer and use it in GitHub Desktop.
Backoff policy with no external fields for counter.
This file contains 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
var backoffPolicy = []int64{0, 10, 30, 60, 300, 300, 900, 900, 900, 1800} | |
func BackoffTime(t int64, base int64) int64 { | |
r := t % 10 | |
// use base var to avoid creating another variable | |
// round base to upper value multiple of ten seconds | |
// and add backoff time | |
base += 10 - base%10 + backoffPolicy[r] + r | |
if r != 9 { | |
base++ | |
} | |
return base | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment