Проверка и завершение требований уровней «3» и «4»

This commit is contained in:
Grbisba
2026-11-06 13:58:50 +03:00
parent 711754bbcd
commit 08ee3fe0b8
30 changed files with 1752 additions and 92 deletions
+15
View File
@@ -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()),