From 678ec77e688030aa845f48619f4164c9d36c4a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Thu, 25 Feb 2021 16:06:49 +0100 Subject: [PATCH] Use `timed.Periodic` when running the periodic scans of filestream --- 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) {