Spaces:
Sleeping
Sleeping
Dhruva P Gowda commited on
Commit ·
7e33fdb
1
Parent(s): 85c3fff
Fix backend startup: resolve relative import error and add graceful fallback for background detector
Browse files- backend/Dockerfile +2 -2
- backend/app/main.py +22 -14
- render.yaml +2 -1
backend/Dockerfile
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
WORKDIR /app
|
| 3 |
RUN apt-get update && apt-get install -y gcc g++ && rm -rf /var/lib/apt/lists/*
|
| 4 |
-
COPY requirements.txt .
|
| 5 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 6 |
COPY . .
|
| 7 |
ENV PORT=8080
|
| 8 |
-
CMD uvicorn app.main:app --host 0.0.0.0 --port ${PORT}
|
|
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
WORKDIR /app
|
| 3 |
RUN apt-get update && apt-get install -y gcc g++ && rm -rf /var/lib/apt/lists/*
|
| 4 |
+
COPY backend/requirements.txt .
|
| 5 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 6 |
COPY . .
|
| 7 |
ENV PORT=8080
|
| 8 |
+
CMD uvicorn backend.app.main:app --host 0.0.0.0 --port ${PORT}
|
backend/app/main.py
CHANGED
|
@@ -166,20 +166,28 @@ async def startup_event():
|
|
| 166 |
except Exception as e:
|
| 167 |
logger.warning(f"GNN loading failed: {e}")
|
| 168 |
|
| 169 |
-
# Start Background Shock Detector if
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
logger.info("PharmaShield startup sequence complete.")
|
| 184 |
|
| 185 |
@app.exception_handler(Exception)
|
|
|
|
| 166 |
except Exception as e:
|
| 167 |
logger.warning(f"GNN loading failed: {e}")
|
| 168 |
|
| 169 |
+
# Start Background Shock Detector — optional; never crash the server if unavailable
|
| 170 |
+
try:
|
| 171 |
+
import sys, os
|
| 172 |
+
# Ensure the project root is on sys.path so 'ingestion' is importable
|
| 173 |
+
project_root = str(Path(__file__).resolve().parent.parent.parent)
|
| 174 |
+
if project_root not in sys.path:
|
| 175 |
+
sys.path.insert(0, project_root)
|
| 176 |
+
|
| 177 |
+
if settings.DEMO_MODE:
|
| 178 |
+
from ingestion.shock_detector import run_once
|
| 179 |
+
loop = asyncio.get_event_loop()
|
| 180 |
+
loop.run_in_executor(None, run_once)
|
| 181 |
+
logger.info("Background detector triggered once (Demo Mode).")
|
| 182 |
+
else:
|
| 183 |
+
from ingestion.shock_detector import run_scheduler
|
| 184 |
+
import threading
|
| 185 |
+
thread = threading.Thread(target=run_scheduler, daemon=True)
|
| 186 |
+
thread.start()
|
| 187 |
+
logger.info("Background detector thread started (Live Mode).")
|
| 188 |
+
except Exception as e:
|
| 189 |
+
logger.warning(f"Shock detector could not start (non-fatal): {e}")
|
| 190 |
+
|
| 191 |
logger.info("PharmaShield startup sequence complete.")
|
| 192 |
|
| 193 |
@app.exception_handler(Exception)
|
render.yaml
CHANGED
|
@@ -5,7 +5,8 @@ services:
|
|
| 5 |
region: singapore
|
| 6 |
plan: free
|
| 7 |
healthCheckPath: /healthz
|
| 8 |
-
rootDir:
|
|
|
|
| 9 |
envVars:
|
| 10 |
- key: GEMINI_API_KEY
|
| 11 |
sync: false
|
|
|
|
| 5 |
region: singapore
|
| 6 |
plan: free
|
| 7 |
healthCheckPath: /healthz
|
| 8 |
+
rootDir: .
|
| 9 |
+
dockerFilePath: backend/Dockerfile
|
| 10 |
envVars:
|
| 11 |
- key: GEMINI_API_KEY
|
| 12 |
sync: false
|