diff --git a/cmd/icingadb/main.go b/cmd/icingadb/main.go index 06449802..164a43db 100644 --- a/cmd/icingadb/main.go +++ b/cmd/icingadb/main.go @@ -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) }