Skip to content

Commit

Permalink
fix: exit gracefully on SIGTERM
Browse files Browse the repository at this point in the history
  • Loading branch information
smlx committed May 6, 2024
1 parent f5468da commit 30844f0
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions cmd/lagoon-opensearch-sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 30844f0

Please sign in to comment.