define playback retry rules and states

This commit is contained in:
Dmitry Sergeev
2026-08-27 00:43:08 +03:00
parent c9f237d9f1
commit 1eaab14793
5 changed files with 128 additions and 9 deletions
+23
View File
@@ -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
}