Skip to content

Commit

Permalink
[FIX] Fixing database connections (#692)
Browse files Browse the repository at this point in the history
fix/fixing database connections
  • Loading branch information
harini-venkataraman authored Sep 14, 2024
1 parent b9f0609 commit 8debcd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions platform-service/src/unstract/platform_service/run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from logging.config import dictConfig
from typing import Any

from dotenv import load_dotenv
from flask import Flask
Expand Down Expand Up @@ -43,6 +44,13 @@ def before_request() -> None:
be_db.connect(reuse_if_open=True)


@app.teardown_request
def after_request(exception: Any) -> None:
# Close the connection after each request
if not be_db.is_closed():
be_db.close()


if __name__ == "__main__":
# Start the server
app.run(host="0.0.0.0", port=3001, load_dotenv=True)
7 changes: 7 additions & 0 deletions prompt-service/src/unstract/prompt_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def before_request() -> None:
db.connect(reuse_if_open=True)


@app.teardown_request
def after_request(exception: Any) -> None:
# Close the connection after each request
if not db.is_closed():
db.close()


def _publish_log(
log_events_id: str,
component: dict[str, str],
Expand Down

0 comments on commit 8debcd7

Please sign in to comment.