Skip to content

Commit 7f6cbf5

Browse files
committed
add db variables to env
1 parent 06ce038 commit 7f6cbf5

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ In the project root directory, create a new `.env` file to define your specific
2222
DATABASE_URL=postgresql://<username>:<password>@<host>:<port>/<database>
2323
PROXY_PATH=ihr/api
2424
PAGE_SIZE=100000
25+
POOL_SIZE=10
26+
MAX_OVERFLOW=5
27+
POOL_TIMEOUT=10
28+
POOL_RECYCLE=1800
2529
REQUEST_TIMEOUT=30
2630
```
2731

config/database.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
except:
1111
pass
1212

13+
POOL_SIZE = int(os.getenv("POOL_SIZE"))
14+
MAX_OVERFLOW = int(os.getenv("MAX_OVERFLOW"))
15+
POOL_TIMEOUT = int(os.getenv("POOL_TIMEOUT"))
16+
POOL_RECYCLE = int(os.getenv("POOL_RECYCLE"))
1317
REQUEST_TIMEOUT = float(os.getenv("REQUEST_TIMEOUT"))
1418
_statement_timeout_ms = int(REQUEST_TIMEOUT * 1000)
1519

@@ -19,14 +23,14 @@
1923
# Create the SQLAlchemy engine with the database URL.
2024
# pool_size / max_overflow cap concurrent DB connections so one slow
2125
# query can't starve the whole server. statement_timeout kills any
22-
# single query that runs longer than 30 s so a runaway request doesn't
26+
# single query that runs longer than N sec so a runaway request doesn't
2327
# hold a connection indefinitely.
2428
engine = create_engine(
2529
DATABASE_URL,
26-
pool_size=10,
27-
max_overflow=5,
28-
pool_timeout=10,
29-
pool_recycle=1800,
30+
pool_size=POOL_SIZE,
31+
max_overflow=MAX_OVERFLOW,
32+
pool_timeout=POOL_TIMEOUT,
33+
pool_recycle=POOL_RECYCLE,
3034
pool_pre_ping=True,
3135
connect_args={"options": f"-c statement_timeout={_statement_timeout_ms}"},
3236
)

main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
root_path="" if PROXY_PATH is None else f"/{PROXY_PATH}",
5454
title="IHR API",
5555
description=description,
56-
version="v2.1",
56+
version="v2.2",
5757
redoc_url=None,
5858
swagger_ui_parameters={ "defaultModelsExpandDepth": -1 },
5959
)
@@ -95,7 +95,8 @@ async def access_logging_middleware(request: Request, call_next):
9595
finally:
9696
duration_s = time.perf_counter() - start
9797
client = request.client.host if request.client else "unknown"
98-
msg = '%s - "%s %s" %s %.3fs', client, request.method, request.url.path, status, duration_s
98+
path = request.url.path + ("?" + str(request.url.query) if request.url.query else "")
99+
msg = '%s - "%s %s" %s %.3fs', client, request.method, path, status, duration_s
99100
if status >= 500:
100101
logger.error(*msg)
101102
elif status >= 400:

0 commit comments

Comments
 (0)