Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ ENV PATH="/app/.venv/bin:$PATH" \
EXPOSE 8080

HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD python -c "import os; import urllib.request; urllib.request.urlopen(f'http://localhost:{os.getenv(\"SYFT_PORT\", \"8080\")}/health')" || exit 1
CMD python -c "import os; import urllib.request; urllib.request.urlopen(f'http://localhost:{os.getenv(\"SYFT_PORT\", \"8080\")}/api/v1/health')" || exit 1

ENTRYPOINT ["/bin/sh", "-c", "exec python -m uvicorn syft_space.main:app --host 0.0.0.0 --port ${SYFT_PORT:-8080}"]
5 changes: 5 additions & 0 deletions backend/syft_space/components/shared/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def set_sqlite_pragma(dbapi_conn, connection_record):
cursor.close()
# logger.debug("SQLite PRAGMA foreign_keys=ON set for new connection")

async def dispose(self) -> None:
"""Dispose of the engine and close all pooled connections."""
await self.engine.dispose()
logger.info("Database engine disposed")

@asynccontextmanager
async def get_session(self) -> AsyncGenerator[SQLModelAsyncSession, None]:
"""Get an async session for the database"""
Expand Down
3 changes: 3 additions & 0 deletions backend/syft_space/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ async def lifespan(app: FastAPI):
except Exception as e:
logger.error(f"Error shutting down {name}: {e}")

# 9. Dispose database engine (close all pooled connections)
await database.dispose()


# Initialize FastAPI app
app = FastAPI(
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ services:

# Health check using Python (no curl in distroless image)
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8080/health')"]
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8080/api/v1/health')"]
interval: 30s
timeout: 10s
retries: 3
Expand Down
Loading