Skip to content

Commit

Permalink
Allows to define database engine pool size and max overflow values (#…
Browse files Browse the repository at this point in the history
…1899)

* Allows to define database engine pool size and max overflow

* Removes unnecessary string cast
  • Loading branch information
mvilanova authored Jan 13, 2022
1 parent 1efdfeb commit 4092d2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/dispatch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def __repr__(self) -> str:
def __str__(self) -> str:
return self._decrypted_value


elif SECRET_PROVIDER == "kms-secret":
import boto3

Expand All @@ -83,7 +82,6 @@ def __repr__(self) -> str:
def __str__(self) -> str:
return self._decrypted_value


else:
from starlette.datastructures import Secret

Expand Down Expand Up @@ -175,6 +173,8 @@ def __str__(self) -> str:
_QUOTED_DATABASE_PASSWORD = parse.quote(str(_DATABASE_CREDENTIAL_PASSWORD))
DATABASE_NAME = config("DATABASE_NAME", default="dispatch")
DATABASE_PORT = config("DATABASE_PORT", default="5432")
DATABASE_ENGINE_POOL_SIZE = config("DATABASE_ENGINE_POOL_SIZE", cast=int, default=1000)
DATABASE_ENGINE_MAX_OVERFLOW = config("DATABASE_ENGINE_MAX_OVERFLOW", cast=int, default=0)
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{_DATABASE_CREDENTIAL_USER}:{_QUOTED_DATABASE_PASSWORD}@{DATABASE_HOSTNAME}:{DATABASE_PORT}/{DATABASE_NAME}"

ALEMBIC_CORE_REVISION_PATH = config(
Expand Down
6 changes: 5 additions & 1 deletion src/dispatch/database/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
from dispatch.search.fulltext import make_searchable


engine = create_engine(str(config.SQLALCHEMY_DATABASE_URI))
engine = create_engine(
config.SQLALCHEMY_DATABASE_URI,
pool_size=config.DATABASE_ENGINE_POOL_SIZE,
max_overflow=config.DATABASE_ENGINE_MAX_OVERFLOW,
)
SessionLocal = sessionmaker(bind=engine)


Expand Down

0 comments on commit 4092d2d

Please sign in to comment.