forked from mtusi2026/mtusi2026lab3
feat: implement estim 4
This commit is contained in:
+10
-3
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user