diff --git a/cmd/lagoon-opensearch-sync/sync.go b/cmd/lagoon-opensearch-sync/sync.go index fb47e08..4451cd6 100644 --- a/cmd/lagoon-opensearch-sync/sync.go +++ b/cmd/lagoon-opensearch-sync/sync.go @@ -86,13 +86,17 @@ func (cmd *SyncCmd) Run(log *zap.Logger) error { return nil } // continue running in a loop - tick := time.NewTicker(cmd.Period) - for range tick.C { - err = sync.Sync(ctx, log, l, k, o, d, cmd.DryRun, cmd.Objects, - cmd.LegacyIndexPatternDelimiter) - if err != nil { - return err + ticker := time.NewTicker(cmd.Period) + for { + select { + case <-ctx.Done(): + return nil + case <-ticker.C: + err = sync.Sync(ctx, log, l, k, o, d, cmd.DryRun, cmd.Objects, + cmd.LegacyIndexPatternDelimiter) + if err != nil { + return err + } } } - return nil }