55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
"""Runtime checks shared by the controller's interpreter probe and workers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
|
|
|
|
def storage_backend(config) -> str:
|
|
"""Return the effective LangGraph persistence adapter selected by config."""
|
|
checkpoint = getattr(config, "checkpointer", None)
|
|
if checkpoint is not None:
|
|
if checkpoint.type == "postgres":
|
|
from deerflow.runtime.checkpointer.async_provider import _use_postgres_enabled
|
|
|
|
return "postgres" if _use_postgres_enabled(checkpoint) else "sqlite"
|
|
if checkpoint.type == "sqlite":
|
|
return "sqlite"
|
|
return "memory"
|
|
|
|
database = getattr(config, "database", None)
|
|
backend = getattr(database, "backend", "memory")
|
|
return backend if backend in {"postgres", "sqlite"} else "memory"
|
|
|
|
|
|
def verify_storage_dependencies(config) -> str:
|
|
"""Verify the adapters the configured runtime will import, without DB access."""
|
|
backend = storage_backend(config)
|
|
modules = {
|
|
"postgres": (
|
|
"langgraph.checkpoint.postgres.aio",
|
|
"langgraph.store.postgres.aio",
|
|
"psycopg.rows",
|
|
"psycopg_pool",
|
|
),
|
|
"sqlite": (
|
|
"langgraph.checkpoint.sqlite.aio",
|
|
"langgraph.store.sqlite.aio",
|
|
),
|
|
}.get(backend, ())
|
|
for module in modules:
|
|
try:
|
|
importlib.import_module(module)
|
|
except ImportError as exc:
|
|
install = (
|
|
"langgraph-checkpoint-postgres psycopg[binary] psycopg-pool"
|
|
if backend == "postgres"
|
|
else "langgraph-checkpoint-sqlite aiosqlite"
|
|
)
|
|
raise RuntimeError(
|
|
f"Worker Python is missing {module} required by the configured "
|
|
f"{backend} chat store; install {install} in the main service "
|
|
"runtime and ensure Workers use that same Python environment"
|
|
) from exc
|
|
return backend
|