mirror of
https://github.com/Luzifer/go-latestver.git
synced 2024-11-09 23:50:05 +00:00
Prevent duplicate execution due to truncating to second
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
128eb0f8ba
commit
984f2a568c
2 changed files with 4 additions and 2 deletions
2
main.go
2
main.go
|
@ -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()
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue