updated models

This commit is contained in:
Ravi Prasad
2025-05-29 01:21:40 -05:00
parent 47ea78901a
commit e29307e848
5 changed files with 37 additions and 9 deletions
+6 -3
View File
@@ -2,6 +2,7 @@
package utils
import (
"log"
"math/rand"
"time"
)
@@ -12,12 +13,14 @@ func init() {
}
// SleepWithJitter sleeps for the given base duration plus or minus 25% random jitter.
// This helps to avoid perfectly uniform request intervals.
// It also logs the actual sleep duration so you can verify it fired correctly.
func SleepWithJitter(base time.Duration) {
half := base / 2
// Random value in [0, half)
randOffset := time.Duration(rand.Int63n(int64(half)))
// Shift to center jitter around zero: [-half/2, +half/2)
delta := randOffset - half/2
time.Sleep(base + delta)
}
actual := base + delta
log.Printf("⏱️ Sleeping for %v (base=%v, jitter=%v)", actual, base, delta)
time.Sleep(actual)
}