forked from mtusi2026/mtusi2026lab2
Проверка и завершение требований уровней «3» и «4»
This commit is contained in:
@@ -3,6 +3,8 @@ package postgres
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
@@ -15,6 +17,11 @@ type ConfigWithLog interface {
|
||||
GetLogLevel() string
|
||||
}
|
||||
|
||||
type ConfigWithTimeouts interface {
|
||||
GetConnectTimeout() time.Duration
|
||||
GetQueryTimeout() time.Duration
|
||||
}
|
||||
|
||||
type ConfigWithMaxConn interface {
|
||||
GetMaxConnections() int32
|
||||
}
|
||||
@@ -47,6 +54,14 @@ func New(cfg MigrationConfig, afterConnect ...AfterConnect) *pgxpool.Pool {
|
||||
}
|
||||
|
||||
addMaxConnectionsToCfg(cfg, poolConfig)
|
||||
if timeoutCfg, ok := cfg.(ConfigWithTimeouts); ok {
|
||||
poolConfig.ConnConfig.ConnectTimeout = timeoutCfg.GetConnectTimeout()
|
||||
poolConfig.ConnConfig.RuntimeParams["statement_timeout"] = strconv.FormatInt(timeoutCfg.GetQueryTimeout().Milliseconds(), 10)
|
||||
}
|
||||
poolConfig.ConnConfig.RuntimeParams["application_name"] = "mtusi-api"
|
||||
slog.Info("postgres_pool_config", "max_conns", poolConfig.MaxConns,
|
||||
"connect_timeout", poolConfig.ConnConfig.ConnectTimeout,
|
||||
"statement_timeout_ms", poolConfig.ConnConfig.RuntimeParams["statement_timeout"])
|
||||
|
||||
poolConfig.ConnConfig.Tracer = &tracelog.TraceLog{
|
||||
Logger: pgxslog.NewLogger(slog.Default()),
|
||||
|
||||
Reference in New Issue
Block a user