Support config SQLAlchemy pool_pre_ping option from env (#1883) (#1903)

Co-authored-by: Zhang Cheng <chengzhang@natureself.cn>
Co-authored-by: Kevin Burnett <18027+burnettk@users.noreply.github.com>
This commit is contained in:
Stephen Zhang 2024-07-12 00:51:49 +08:00 committed by GitHub
parent 0761505096
commit 8f86ff5f84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View File

@ -72,8 +72,13 @@ def setup_database_configs(app: Flask) -> None:
# this is a sqlalchemy default, if we don't have any better ideas # this is a sqlalchemy default, if we don't have any better ideas
pool_size = 5 pool_size = 5
pool_pre_ping = app.config.get("SPIFFWORKFLOW_BACKEND_DATABASE_POOL_PRE_PING")
if pool_pre_ping is None:
pool_pre_ping = True
app.config["SQLALCHEMY_ENGINE_OPTIONS"] = {} app.config["SQLALCHEMY_ENGINE_OPTIONS"] = {}
app.config["SQLALCHEMY_ENGINE_OPTIONS"]["pool_size"] = pool_size app.config["SQLALCHEMY_ENGINE_OPTIONS"]["pool_size"] = pool_size
app.config["SQLALCHEMY_ENGINE_OPTIONS"]["pool_pre_ping"] = pool_pre_ping
def load_config_file(app: Flask, env_config_module: str) -> None: def load_config_file(app: Flask, env_config_module: str) -> None:

View File

@ -107,6 +107,9 @@ config_from_env("SPIFFWORKFLOW_BACKEND_DATABASE_URI")
config_from_env("SPIFFWORKFLOW_BACKEND_DATABASE_PASSWORD") config_from_env("SPIFFWORKFLOW_BACKEND_DATABASE_PASSWORD")
# we only use this in one place, and it checks to see if it is None. # we only use this in one place, and it checks to see if it is None.
config_from_env("SPIFFWORKFLOW_BACKEND_DATABASE_POOL_SIZE") config_from_env("SPIFFWORKFLOW_BACKEND_DATABASE_POOL_SIZE")
# check sqlalchemy's doc for more info about pool_pre_ping:
# https://docs.sqlalchemy.org/en/20/core/pooling.html#disconnect-handling-pessimistic
config_from_env("SPIFFWORKFLOW_BACKEND_DATABASE_POOL_PRE_PING", default=True)
### open id ### open id
config_from_env("SPIFFWORKFLOW_BACKEND_AUTHENTICATION_DISABLED", default=False) config_from_env("SPIFFWORKFLOW_BACKEND_AUTHENTICATION_DISABLED", default=False)