Добавить X-Instance-Id, задержку drain при SIGTERM и отдельный запуск миграций
This commit is contained in:
+9
-2
@@ -25,6 +25,8 @@ import (
|
||||
type App struct {
|
||||
Engine *gin.Engine
|
||||
Health *health.Handler
|
||||
// Chats is exposed for the background cleanup of idempotency keys.
|
||||
Chats *chat.Service
|
||||
}
|
||||
|
||||
// Deps are the shared resources the modules are built on; their lifetime is
|
||||
@@ -37,6 +39,11 @@ type Deps struct {
|
||||
MaxBodyBytes int64
|
||||
// RequestTimeout bounds every API request; zero means the default.
|
||||
RequestTimeout time.Duration
|
||||
// InstanceID is sent as X-Instance-Id on every response.
|
||||
InstanceID string
|
||||
// IdempotencyTTL is how long a message Idempotency-Key is remembered;
|
||||
// zero means the default.
|
||||
IdempotencyTTL time.Duration
|
||||
}
|
||||
|
||||
// defaultRequestTimeout stays below the server's 10s write timeout, so a
|
||||
@@ -47,7 +54,7 @@ func New(d Deps) *App {
|
||||
users := user.NewService(userstore.NewUsers(d.DB))
|
||||
chats := chat.NewService(chatstore.NewChats(d.DB), chatstore.NewMessages(d.DB), users)
|
||||
|
||||
engine := httpx.NewEngine(d.Log, d.MaxBodyBytes)
|
||||
engine := httpx.NewEngine(d.Log, d.MaxBodyBytes, d.InstanceID)
|
||||
probes := health.New(
|
||||
health.Check{Name: "postgres", Probe: d.DB.Ping},
|
||||
health.Check{Name: "valkey", Probe: func(ctx context.Context) error { return d.Sessions.Ping(ctx).Err() }},
|
||||
@@ -66,5 +73,5 @@ func New(d Deps) *App {
|
||||
user.NewHandler(users).Register(public, protected)
|
||||
chat.NewHandler(chats).Register(protected)
|
||||
|
||||
return &App{Engine: engine, Health: probes}
|
||||
return &App{Engine: engine, Health: probes, Chats: chats}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user