Merge branch 'ji' of http://192.168.0.200/knowledge-base-bj/deerflow-server into ji
This commit is contained in:
commit
24db448cfd
10 files changed
+555
-146
No files matched your search
+38
-2
@@ -28,6 +28,42 @@ from deerflow.runtime.store.provider import POSTGRES_CONN_REQUIRED, POSTGRES_STO
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _pool_size_env(name: str, default: int) -> int:
|
||||
import os
|
||||
|
||||
raw = os.getenv(name, "").strip()
|
||||
if not raw:
|
||||
return default
|
||||
try:
|
||||
return max(0, int(raw))
|
||||
except ValueError:
|
||||
logger.warning("Invalid %s=%r; using default %d", name, raw, default)
|
||||
return default
|
||||
|
||||
|
||||
def _postgres_pool_config() -> dict:
|
||||
"""Pool config for the Postgres store.
|
||||
|
||||
A single long-lived connection (the default ``from_conn_string`` behavior)
|
||||
dies permanently on a server restart / idle timeout / network blip — every
|
||||
later store call then fails with "server closed the connection
|
||||
unexpectedly". A pool with ``check=check_connection`` validates each
|
||||
connection on checkout and replaces dead ones, so the runtime self-heals.
|
||||
Extra keys (``check``/``max_idle``/``max_lifetime``) are passed straight
|
||||
through to ``AsyncConnectionPool`` by ``from_conn_string``.
|
||||
"""
|
||||
from psycopg_pool import AsyncConnectionPool
|
||||
|
||||
return {
|
||||
"min_size": _pool_size_env("DEER_FLOW_PG_POOL_MIN", 1),
|
||||
"max_size": _pool_size_env("DEER_FLOW_PG_POOL_MAX", 10),
|
||||
"check": AsyncConnectionPool.check_connection,
|
||||
"max_idle": 300.0,
|
||||
"max_lifetime": 3600.0,
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Internal backend factory
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -71,9 +107,9 @@ async def _async_store(config) -> AsyncIterator[BaseStore]:
|
||||
if not config.connection_string:
|
||||
raise ValueError(POSTGRES_CONN_REQUIRED)
|
||||
|
||||
async with AsyncPostgresStore.from_conn_string(config.connection_string) as store:
|
||||
async with AsyncPostgresStore.from_conn_string(config.connection_string, pool_config=_postgres_pool_config()) as store:
|
||||
await store.setup()
|
||||
logger.info("Store: using AsyncPostgresStore")
|
||||
logger.info("Store: using AsyncPostgresStore (pooled, self-healing)")
|
||||
yield store
|
||||
return
|
||||
|
||||
|
||||
Reference in new issue
Block a user