refactor: replace timer with ticker

This commit is contained in:
Mohamed Sohail 2023-02-24 08:06:07 +00:00
parent 4b2eb7b018
commit 0d5bc3a333
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D

View File

@ -48,20 +48,18 @@ func NewJanitor(o JanitorOpts) *Janitor {
} }
func (j *Janitor) Start(ctx context.Context) error { func (j *Janitor) Start(ctx context.Context) error {
timer := time.NewTimer(j.sweepInterval) ticker := time.NewTicker(j.sweepInterval)
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
j.logg.Info("janitor: shutdown signal received") j.logg.Info("janitor: shutdown signal received")
return nil return nil
case <-timer.C: case <-ticker.C:
j.logg.Debug("janitor: starting sweep") j.logg.Debug("janitor: starting sweep")
if err := j.QueueMissingBlocks(context.Background()); err != nil { if err := j.QueueMissingBlocks(context.Background()); err != nil {
j.logg.Error("janitor: queue missing blocks error", "error", err) j.logg.Error("janitor: queue missing blocks error", "error", err)
} }
timer.Reset(j.sweepInterval)
} }
} }
} }