feat: implement estim 4

This commit is contained in:
2026-11-06 05:12:28 +03:00
parent ec111aadfb
commit b48e71f433
29 changed files with 504 additions and 194 deletions
+10 -3
View File
@@ -18,7 +18,10 @@ import (
"messenger/internal/service"
)
const shutdownTimeout = 5 * time.Second
const (
drainDelay = 3 * time.Second
shutdownTimeout = 5 * time.Second
)
func main() {
log := slog.New(slog.NewJSONHandler(os.Stdout, nil))
@@ -59,9 +62,10 @@ func run(log *slog.Logger) error {
messages := service.NewMessageService(chats, store)
deps := []handler.Pinger{store.Ping, sessions.Ping}
h := handler.New(users, auth, chats, messages, deps, log)
srv := &http.Server{
Addr: cfg.Addr(),
Handler: router.New(handler.New(users, auth, chats, messages, deps, log), instanceID),
Handler: router.New(h, instanceID),
ReadHeaderTimeout: 5 * time.Second,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
@@ -84,7 +88,10 @@ func run(log *slog.Logger) error {
return err
case <-ctx.Done():
}
log.Info("shutdown signal received", "timeout", shutdownTimeout.String())
log.Info("shutdown signal received, draining", "drain", drainDelay.String(), "timeout", shutdownTimeout.String())
h.StartDraining()
srv.SetKeepAlivesEnabled(false)
time.Sleep(drainDelay)
shutdownCtx, cancel := context.WithTimeout(context.Background(), shutdownTimeout)
defer cancel()