Spaces:
Running
Running
Commit ·
21da995
1
Parent(s): db90335
fix: single worker + graceful table creation for Neon
Browse files- backend/app/main.py +23 -20
- supervisord.conf +1 -1
backend/app/main.py
CHANGED
|
@@ -31,26 +31,29 @@ async def lifespan(app: FastAPI):
|
|
| 31 |
logger.info("Starting %s v%s", settings.app_name, settings.app_version)
|
| 32 |
|
| 33 |
# Create database tables
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
# Seed exchange data
|
| 56 |
await _seed_exchanges()
|
|
|
|
| 31 |
logger.info("Starting %s v%s", settings.app_name, settings.app_version)
|
| 32 |
|
| 33 |
# Create database tables
|
| 34 |
+
try:
|
| 35 |
+
async with engine.begin() as conn:
|
| 36 |
+
from app.models import ( # noqa: F401 — force model registration
|
| 37 |
+
Asset,
|
| 38 |
+
BacktestResult,
|
| 39 |
+
Exchange,
|
| 40 |
+
Factor,
|
| 41 |
+
FactorExposure,
|
| 42 |
+
FeatureData,
|
| 43 |
+
Holding,
|
| 44 |
+
MarketplaceEntry,
|
| 45 |
+
NewsArticle,
|
| 46 |
+
Portfolio,
|
| 47 |
+
PriceData,
|
| 48 |
+
ResearchReport,
|
| 49 |
+
Signal,
|
| 50 |
+
Strategy,
|
| 51 |
+
User,
|
| 52 |
+
)
|
| 53 |
+
await conn.run_sync(Base.metadata.create_all)
|
| 54 |
+
logger.info("Database tables created successfully")
|
| 55 |
+
except Exception as e:
|
| 56 |
+
logger.warning("Table creation skipped (tables may already exist): %s", e)
|
| 57 |
|
| 58 |
# Seed exchange data
|
| 59 |
await _seed_exchanges()
|
supervisord.conf
CHANGED
|
@@ -15,7 +15,7 @@ stderr_logfile=/dev/stderr
|
|
| 15 |
stderr_logfile_maxbytes=0
|
| 16 |
|
| 17 |
[program:uvicorn]
|
| 18 |
-
command=uvicorn app.main:app --host 127.0.0.1 --port 8000 --workers
|
| 19 |
directory=/app
|
| 20 |
autostart=true
|
| 21 |
autorestart=true
|
|
|
|
| 15 |
stderr_logfile_maxbytes=0
|
| 16 |
|
| 17 |
[program:uvicorn]
|
| 18 |
+
command=uvicorn app.main:app --host 127.0.0.1 --port 8000 --workers 1 --timeout-keep-alive 120
|
| 19 |
directory=/app
|
| 20 |
autostart=true
|
| 21 |
autorestart=true
|