Skip to content

Commit

Permalink
Add db pool recycle conf
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Bui-Quang <[email protected]>
  • Loading branch information
pl-buiquang committed Feb 21, 2022
1 parent ae62f1d commit aeca946
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions antarest/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ class DbConfig:
db_url: str = ""
db_admin_url: Optional[str] = None
db_connect_timeout: int = 10
pool_recycle: Optional[int] = None

@staticmethod
def from_dict(data: JSON) -> "DbConfig":
return DbConfig(
db_admin_url=data.get("admin_url", None),
db_url=data.get("url", ""),
db_connect_timeout=data.get("db_connect_timeout", 10),
pool_recycle=data.get("pool_recycle", None),
)


Expand Down
8 changes: 5 additions & 3 deletions antarest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ def init_db(
else:
connect_args["connect_timeout"] = config.db.db_connect_timeout

extra = {}
if config.db.pool_recycle:
extra["pool_recycle"] = config.db.pool_recycle

engine = create_engine(
config.db.db_url,
echo=config.debug,
connect_args=connect_args,
config.db.db_url, echo=config.debug, connect_args=connect_args, **extra
)

session_args = {
Expand Down
1 change: 1 addition & 0 deletions resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ security:

db:
url: "sqlite:///database.db"
#pool_recycle:

storage:
tmp_dir: /tmp
Expand Down

0 comments on commit aeca946

Please sign in to comment.