Prevent duplicate execution due to truncating to second

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-11-29 18:34:14 +01:00
parent 128eb0f8ba
commit 984f2a568c
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
2 changed files with 4 additions and 2 deletions

View file

@ -74,7 +74,7 @@ func main() {
} }
scheduler := cron.New() scheduler := cron.New()
scheduler.AddFunc("@every 1m", schedulerRun) scheduler.AddFunc(fmt.Sprintf("@every %s", schedulerInterval), schedulerRun)
scheduler.Start() scheduler.Start()
router = mux.NewRouter() router = mux.NewRouter()

View file

@ -15,6 +15,8 @@ import (
"github.com/Luzifer/go-latestver/internal/fetcher" "github.com/Luzifer/go-latestver/internal/fetcher"
) )
const schedulerInterval = time.Minute
var schedulerRunActive bool var schedulerRunActive bool
func schedulerRun() { func schedulerRun() {
@ -110,7 +112,7 @@ func nextCheckTime(ce *database.CatalogEntry, lastCheck *time.Time) time.Time {
Truncate(cfg.CheckDistribution). Truncate(cfg.CheckDistribution).
Add(time.Duration(jitter) % cfg.CheckDistribution) Add(time.Duration(jitter) % cfg.CheckDistribution)
if next.Before(*lastCheck) { if next.Before((*lastCheck).Add(schedulerInterval)) {
next = next.Add(cfg.CheckDistribution) next = next.Add(cfg.CheckDistribution)
} }