From f7b9f538b428d6c6b582e3b665e915e06440d1da Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Wed, 17 May 2023 06:05:37 +0000 Subject: [PATCH] fix: wait 10 seconds before query with new limit --- distro/debian/snapshot/mr/mr.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/distro/debian/snapshot/mr/mr.go b/distro/debian/snapshot/mr/mr.go index 34d6d3d..e3c990b 100644 --- a/distro/debian/snapshot/mr/mr.go +++ b/distro/debian/snapshot/mr/mr.go @@ -16,8 +16,9 @@ import ( const apiURL = "https://snapshot.debian.org/mr" var ( - limiterTimeout time.Duration = time.Second / 20 - limiterBurst int = 3 + limiterTimeout time.Duration = time.Second / 20 + limiterBurst int = 3 + limiterUpdateDelay time.Duration = time.Second * 10 Limiter = rate.NewLimiter(rate.Every(limiterTimeout), limiterBurst) ) @@ -25,7 +26,10 @@ var ( func lowerLimit() { limiterTimeout = limiterTimeout * 2 log.Info().Msgf("limiter timeout set to %v", limiterTimeout) - Limiter.SetLimit(rate.Every(limiterTimeout)) + Limiter.SetLimitAt( + time.Now().Add(limiterUpdateDelay), + rate.Every(limiterTimeout), + ) } // Retries in case of 5xx errors