mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-05-03 16:09:37 -05:00
feat: dlq for dispatcher queues (#2600)
* feat: dlq for dispatcher queues * reduce dispatcher message ttl to 20 seconds * rename dispatcher queue for clarity * add error logs when dead lettering * address comment
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package queueutils
|
||||
|
||||
import (
|
||||
"math"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
@@ -13,9 +14,17 @@ func SleepWithExponentialBackoff(base, max time.Duration, retryCount int) { // n
|
||||
retryCount = 0
|
||||
}
|
||||
|
||||
// prevent overflow
|
||||
pow := time.Duration(math.MaxInt64)
|
||||
if retryCount < 63 {
|
||||
pow = 1 << retryCount
|
||||
}
|
||||
|
||||
// Calculate exponential backoff
|
||||
backoff := base * (1 << retryCount)
|
||||
if backoff > max {
|
||||
backoff := base * pow
|
||||
|
||||
// if backoff / pow does not recover base, we've overflowed
|
||||
if backoff > max || backoff/pow != base {
|
||||
backoff = max
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user