Properly shutdown database on SIGTERM

This commit is contained in:
2022-12-22 10:21:10 +01:00
parent dbc014f819
commit f65c231ba0
4 changed files with 25 additions and 4 deletions

View File

@@ -91,15 +91,15 @@ func (app *Application) Run() {
errChan <- httpserver.Serve(ln)
}()
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
sigstop := make(chan os.Signal, 1)
signal.Notify(sigstop, os.Interrupt, syscall.SIGTERM)
for _, job := range app.Jobs {
job.Start()
}
select {
case <-stop:
case <-sigstop:
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
@@ -135,6 +135,13 @@ func (app *Application) Run() {
job.Stop()
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
err := app.Database.Stop(ctx)
if err != nil {
log.Info().Err(err).Msg("Error while stopping the database")
}
app.IsRunning.Set(false)
}