Start history retention after config and state sync

Co-authored-by: Eric Lippmann <eric.lippmann@icinga.com>
This commit is contained in:
Ravi Kumar Kempapura Srinivasa 2022-01-31 16:19:23 +01:00 committed by Eric Lippmann
parent 73f4639d35
commit 2c09dd9e1c

View file

@ -131,6 +131,14 @@ func run() int {
hs := history.NewSync(db, rc, logs.GetChildLogger("history-sync"))
rt := icingadb.NewRuntimeUpdates(db, rc, logs.GetChildLogger("runtime-updates"))
ods := overdue.NewSync(db, rc, logs.GetChildLogger("overdue-sync"))
ret := history.NewRetention(
db,
cmd.Config.HistoryRetention.Days,
cmd.Config.HistoryRetention.Interval,
cmd.Config.HistoryRetention.Count,
cmd.Config.HistoryRetention.Options,
logs.GetChildLogger("history-retention"),
)
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
@ -281,6 +289,20 @@ func run() int {
return rt.Sync(synctx, v1.StateFactories, runtimeStateUpdateStreams, true)
})
g.Go(func() error {
// Wait for config and state sync to avoid putting additional pressure on the database.
configInitSync.Wait()
stateInitSync.Wait()
if err := synctx.Err(); err != nil {
return err
}
logger.Info("Starting history retention")
return ret.Start(synctx)
})
if err := g.Wait(); err != nil && !utils.IsContextCanceled(err) {
logger.Fatalf("%+v", err)
}