define playback retry rules and states
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package playback
|
||||
|
||||
import "time"
|
||||
|
||||
func (p RetryPolicy) canRetry(failedAttempts int) bool {
|
||||
return p.MaxAttempts == 0 || failedAttempts < p.MaxAttempts
|
||||
}
|
||||
|
||||
func (p RetryPolicy) retryDelay(failedAttempts int) time.Duration {
|
||||
delay := p.InitialDelay
|
||||
|
||||
for attempt := 1; attempt < failedAttempts; attempt++ {
|
||||
if delay >= p.MaxDelay/2 {
|
||||
return p.MaxDelay
|
||||
}
|
||||
delay *= 2
|
||||
}
|
||||
|
||||
if delay > p.MaxDelay {
|
||||
return p.MaxDelay
|
||||
}
|
||||
return delay
|
||||
}
|
||||
Reference in New Issue
Block a user