Skip to content

Commit

Permalink
update delay functionality in model.ScheduleQuery to make the delay's…
Browse files Browse the repository at this point in the history
… more reasonable and related to the interval
  • Loading branch information
ntbosscher committed Nov 16, 2020
1 parent 42e541f commit 63bdafa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions model/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ func ScheduleRecurringQuery(interval time.Duration, query string) {
}
}()

// delay initial query somewhat randomly to ensure
// we don't block startup and queries with the same interval don't run at exactly the same time
<-time.After(interval / time.Duration(randomish.Int(1, 5)))

tc := time.NewTicker(interval)
defer tc.Stop()

// delay initial query somewhat randomly to ensure
// we don't block startup
<-time.After(time.Duration(5+randomish.Int(0, 10)) * time.Minute)

for {
if err := runQuery(context.Background(), query); err != nil {
log.Println(err)
Expand Down

0 comments on commit 63bdafa

Please sign in to comment.