-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_app.py
51 lines (38 loc) · 1.14 KB
/
main_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
### fastapi app
import sys
sys.path.append("ai_module/src")
import uvicorn
from apscheduler.schedulers.background import BackgroundScheduler
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from backend.db import models
from backend.db.database import engine, get_db
from backend.configs.dependency.preset_class import AiModules
from backend.route.router import api_router
from backend.scheduler.tasks import db_check
models.Base.metadata.create_all(bind=engine)
main_modules = {}
app = FastAPI()
origins = [
"*",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.on_event("startup")
def startup_event():
AiModules() ## initialize ai modules(singleton)
scheduler = BackgroundScheduler()
db = next(get_db())
scheduler.add_job(db_check, 'cron', minute='*/30', kwargs={"db": db})
scheduler.start()
@app.get("/ai/health")
def health_check():
return {"status": "ok"}
app.include_router(api_router)
if __name__ == "__main__":
uvicorn.run("main_app:app", host="0.0.0.0", port=8000, reload=False)