From fe2653760b29e24072853440b6488dc656cd02f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Tue, 2 Mar 2021 16:09:12 +0100 Subject: [PATCH] Use `timed.Periodic` when running the periodic scans of filestream (#24248) --- filebeat/input/filestream/fswatch.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/filebeat/input/filestream/fswatch.go b/filebeat/input/filestream/fswatch.go index 2db95427cadb..0b1e5df46f45 100644 --- a/filebeat/input/filestream/fswatch.go +++ b/filebeat/input/filestream/fswatch.go @@ -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" ) @@ -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) {