Skip to content

Commit

Permalink
fix: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren committed Dec 14, 2024
1 parent ecb1ac0 commit 34b302f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions keep/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from starlette_context import plugins
from starlette_context.middleware import RawContextMiddleware

import keep.api.core.db
import keep.api.logging
import keep.api.observability
import keep.api.utils.import_ee
Expand All @@ -27,6 +26,7 @@
KEEP_ARQ_TASK_POOL_NONE,
)
from keep.api.core.config import config
from keep.api.core.db import dispose_session
from keep.api.core.dependencies import SINGLE_TENANT_UUID
from keep.api.logging import CONFIG as logging_config
from keep.api.middlewares import LoggingMiddleware
Expand Down Expand Up @@ -113,7 +113,7 @@ async def startup():
logger.info("Disope existing DB connections")
# psycopg2.DatabaseError: error with status PGRES_TUPLES_OK and no message from the libpq
# https://stackoverflow.com/questions/43944787/sqlalchemy-celery-with-scoped-session-error/54751019#54751019
keep.api.core.db.engine.dispose()
dispose_session()

logger.info("Starting the services")

Expand Down
9 changes: 9 additions & 0 deletions keep/api/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@
]


def dispose_session():
logger.info("Disposing engine pool")
if engine.dialect.name != "sqlite":
engine.dispose()
logger.info("Engine pool disposed")
else:
logger.info("Engine pool is sqlite, not disposing")


@contextmanager
def existed_or_new_session(session: Optional[Session] = None) -> Session:
if session:
Expand Down

0 comments on commit 34b302f

Please sign in to comment.