From 984f2a568cffef5533fc7d6b444ed7c762812011 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 29 Nov 2021 18:34:14 +0100 Subject: [PATCH] Prevent duplicate execution due to truncating to second Signed-off-by: Knut Ahlers --- main.go | 2 +- scheduler.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index c3d46fb..73ab979 100644 --- a/main.go +++ b/main.go @@ -74,7 +74,7 @@ func main() { } scheduler := cron.New() - scheduler.AddFunc("@every 1m", schedulerRun) + scheduler.AddFunc(fmt.Sprintf("@every %s", schedulerInterval), schedulerRun) scheduler.Start() router = mux.NewRouter() diff --git a/scheduler.go b/scheduler.go index 435565e..29ee9a6 100644 --- a/scheduler.go +++ b/scheduler.go @@ -15,6 +15,8 @@ import ( "github.com/Luzifer/go-latestver/internal/fetcher" ) +const schedulerInterval = time.Minute + var schedulerRunActive bool func schedulerRun() { @@ -110,7 +112,7 @@ func nextCheckTime(ce *database.CatalogEntry, lastCheck *time.Time) time.Time { Truncate(cfg.CheckDistribution). Add(time.Duration(jitter) % cfg.CheckDistribution) - if next.Before(*lastCheck) { + if next.Before((*lastCheck).Add(schedulerInterval)) { next = next.Add(cfg.CheckDistribution) }