feat: 重建 MediaMTX 生命周期与状态对账 (#67)
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package reconcile
|
||||
|
||||
import "time"
|
||||
|
||||
func Backoff(failures int) time.Duration {
|
||||
if failures <= 1 {
|
||||
return time.Second
|
||||
}
|
||||
d := time.Second
|
||||
for i := 1; i < failures; i++ {
|
||||
if d >= 30*time.Second {
|
||||
return time.Minute
|
||||
}
|
||||
d *= 2
|
||||
}
|
||||
return d
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package reconcile
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestBackoffIsBounded(t *testing.T) {
|
||||
if Backoff(1) != time.Second || Backoff(4) != 8*time.Second || Backoff(20) != time.Minute {
|
||||
t.Fatal("unexpected retry backoff")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user