Skip to content

Instantly share code, notes, and snippets.

@rkravchik
Created June 27, 2018 08:18
Show Gist options
  • Save rkravchik/6b5f327d29e4431bf69b5008b2b40947 to your computer and use it in GitHub Desktop.
Save rkravchik/6b5f327d29e4431bf69b5008b2b40947 to your computer and use it in GitHub Desktop.
Backoff policy with no external fields for counter.
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