|
33 | 33 | Text,
|
34 | 34 | create_engine,
|
35 | 35 | func,
|
36 |
| - select, |
37 | 36 | make_url,
|
| 37 | + select, |
38 | 38 | )
|
39 | 39 | from sqlalchemy.event import listen
|
40 | 40 | from sqlalchemy.exc import SQLAlchemyError
|
|
50 | 50 | from mcpgateway.config import settings
|
51 | 51 | from mcpgateway.types import ResourceContent
|
52 | 52 |
|
53 |
| - |
54 | 53 | # ---------------------------------------------------------------------------
|
55 | 54 | # 1. Parse the URL so we can inspect backend ("postgresql", "sqlite", …)
|
56 | 55 | # and the specific driver ("psycopg2", "asyncpg", empty string = default).
|
57 | 56 | # ---------------------------------------------------------------------------
|
58 | 57 | url = make_url(settings.database_url)
|
59 |
| -backend = url.get_backend_name() # e.g. 'postgresql', 'sqlite' |
60 |
| -driver = url.get_driver_name() or "default" |
| 58 | +backend = url.get_backend_name() # e.g. 'postgresql', 'sqlite' |
| 59 | +driver = url.get_driver_name() or "default" |
61 | 60 |
|
62 | 61 | # Start with an empty dict and add options only when the driver can accept
|
63 |
| -# them; this prevents unexpected TypeError at connect time. |
| 62 | +# them; this prevents unexpected TypeError at connect time. |
64 | 63 | connect_args: dict[str, object] = {}
|
65 | 64 |
|
66 | 65 | # ---------------------------------------------------------------------------
|
67 | 66 | # 2. PostgreSQL (synchronous psycopg2 only)
|
68 | 67 | # The keep-alive parameters below are recognised exclusively by libpq /
|
69 |
| -# psycopg2 and let the kernel detect broken network links quickly. |
| 68 | +# psycopg2 and let the kernel detect broken network links quickly. |
70 | 69 | # ---------------------------------------------------------------------------
|
71 | 70 | if backend == "postgresql" and driver in ("psycopg2", "default", ""):
|
72 | 71 | connect_args.update(
|
73 |
| - keepalives=1, # enable TCP keep-alive probes |
74 |
| - keepalives_idle=30, # seconds of idleness before first probe |
75 |
| - keepalives_interval=5, # seconds between probes |
76 |
| - keepalives_count=5, # drop the link after N failed probes |
| 72 | + keepalives=1, # enable TCP keep-alive probes |
| 73 | + keepalives_idle=30, # seconds of idleness before first probe |
| 74 | + keepalives_interval=5, # seconds between probes |
| 75 | + keepalives_count=5, # drop the link after N failed probes |
77 | 76 | )
|
78 | 77 |
|
79 | 78 | # ---------------------------------------------------------------------------
|
|
90 | 89 | # ---------------------------------------------------------------------------
|
91 | 90 | engine = create_engine(
|
92 | 91 | settings.database_url,
|
93 |
| - pool_pre_ping=True, # quick liveness check per checkout |
| 92 | + pool_pre_ping=True, # quick liveness check per checkout |
94 | 93 | pool_size=settings.db_pool_size,
|
95 | 94 | max_overflow=settings.db_max_overflow,
|
96 | 95 | pool_timeout=settings.db_pool_timeout,
|
|
0 commit comments