Skip to content

Commit

Permalink
Use timed.Periodic when running the periodic scans of filestream (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kvch authored Mar 2, 2021
1 parent 34e9bc5 commit fe26537
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions filebeat/input/filestream/fswatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/common/match"
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/go-concert/timed"
"github.com/elastic/go-concert/unison"
)

Expand Down Expand Up @@ -118,16 +119,11 @@ func (w *fileWatcher) Run(ctx unison.Canceler) {
// run initial scan before starting regular
w.watch(ctx)

ticker := time.NewTicker(w.interval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
w.watch(ctx)
}
}
timed.Periodic(ctx, w.interval, func() error {
w.watch(ctx)

return nil
})
}

func (w *fileWatcher) watch(ctx unison.Canceler) {
Expand Down

0 comments on commit fe26537

Please sign in to comment.