f-78: agent: attendre la fin du watchdog avant de fermer la base à l'arrêt #78
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
a47af03eef
commit
54e0faac55
2 changed files with 64 additions and 9 deletions
|
|
@ -111,11 +111,18 @@ func run(confFile string) int {
|
|||
go adminSrv.Start()
|
||||
}
|
||||
|
||||
watchdogStopped := make(chan struct{})
|
||||
if cfg.Watchdog.Enabled {
|
||||
wlog := log.With(slog.String("component", "watchdog"))
|
||||
go watchdog.New(db, cfg, notify.NewStderr(wlog), wlog,
|
||||
w := watchdog.New(db, cfg, notify.NewStderr(wlog), wlog,
|
||||
time.Duration(cfg.Watchdog.IntervalSeconds)*time.Second,
|
||||
).Run(ctx)
|
||||
)
|
||||
go func() {
|
||||
defer close(watchdogStopped)
|
||||
w.Run(ctx)
|
||||
}()
|
||||
} else {
|
||||
close(watchdogStopped)
|
||||
}
|
||||
|
||||
<-ctx.Done()
|
||||
|
|
@ -125,7 +132,7 @@ func run(confFile string) int {
|
|||
if adminSrv != nil {
|
||||
servers["admin"] = adminSrv
|
||||
}
|
||||
closeDB = shutdown(log, q, servers, shutdownTimeout)
|
||||
closeDB = shutdown(log, q, servers, watchdogStopped, shutdownTimeout)
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
@ -149,7 +156,7 @@ type httpShutdowner interface {
|
|||
Shutdown(context.Context) error
|
||||
}
|
||||
|
||||
func shutdown(log *slog.Logger, q *worker.Queue, servers map[string]httpShutdowner, timeout time.Duration) bool {
|
||||
func shutdown(log *slog.Logger, q *worker.Queue, servers map[string]httpShutdowner, watchdogStopped <-chan struct{}, timeout time.Duration) bool {
|
||||
log.Info("shutting down", "timeout", timeout)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
|
|
@ -170,9 +177,16 @@ func shutdown(log *slog.Logger, q *worker.Queue, servers map[string]httpShutdown
|
|||
select {
|
||||
case <-drained:
|
||||
log.Info("workers drained")
|
||||
return true
|
||||
case <-ctx.Done():
|
||||
log.Error("workers still running after timeout, leaving database untouched")
|
||||
return false
|
||||
}
|
||||
|
||||
select {
|
||||
case <-watchdogStopped:
|
||||
return true
|
||||
case <-ctx.Done():
|
||||
log.Error("watchdog still running after timeout, leaving database untouched")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue