sync update from LAN repo (source dhk-1 @ 3b1ec5b4)

This commit is contained in:
gozeros committed 2026-11-05 10:56:34 +08:00
1 parent da6521b6cb
commit 264e2200d6
995 files changed
+148105 -13399

No files matched your search

@@ -44,7 +44,7 @@ from __future__ import annotations
import os
from typing import Literal
from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, field_validator, model_validator
class DatabaseConfig(BaseModel):
@@ -116,6 +116,7 @@ class DatabaseConfig(BaseModel):
default=1800,
description=(
"Recycle pooled connections after this many seconds (postgres/gauss/mysql only). "
"When omitted, PostgreSQL defaults to 300s; other backends default to 1800s. "
"Prevents stale-connection errors when a firewall, pgbouncer, or MySQL "
"wait_timeout silently drops idle connections. pool_pre_ping catches most "
"cases, but pool_recycle is the belt-and-suspenders safety net. "
@@ -123,6 +124,31 @@ class DatabaseConfig(BaseModel):
"connections; total across workers must stay below the DB's max_connections."
),
)
command_timeout: float | None = Field(
default=30,
gt=0,
allow_inf_nan=False,
description=(
"asyncpg command timeout in seconds for the PostgreSQL/openGauss app ORM. "
"Independent of pool_timeout (connection checkout) and the psycopg checkpoint pool. "
"Null disables the command deadline. Not passed to MySQL or SQLite drivers."
),
)
@model_validator(mode="before")
@classmethod
def _postgres_pool_default(cls, values):
# Keep MySQL's existing 1800s default and all explicitly set values.
if isinstance(values, dict) and values.get("backend") == "postgres" and "pool_recycle" not in values:
return {**values, "pool_recycle": 300}
return values
@field_validator("command_timeout", mode="before")
@classmethod
def _reject_boolean_timeout(cls, value):
if isinstance(value, bool):
raise ValueError("command_timeout must be a positive finite number or null")
return value
# -- Derived helpers (not user-configured) --