-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (33 loc) · 1.08 KB
/
main.py
File metadata and controls
43 lines (33 loc) · 1.08 KB
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
from services.user_service.views import user as user_view
from services.workflow_service.views import dag as dag_view, \
project as project_view
from utils.config.environment import ENV
from utils.database.connection import engine
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from sqlalchemy.exc import OperationalError
import logging
logging.basicConfig(
format="%(asctime)s %(levelname)-8s %(message)s",
level=ENV.LOG_LEVEL,
datefmt="%Y-%m-%d %H:%M:%S",
)
app = FastAPI(title="scystream-core")
@app.on_event("startup")
async def test_db_conn():
try:
engine.connect()
except OperationalError:
logging.error("Connection to database failed.")
raise RuntimeError("Shutdown, database connection failed.")
origins = ["*" if ENV.DEVELOPMENT else ENV.EXTERNAL_URL]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(user_view.router)
app.include_router(dag_view.router)
app.include_router(project_view.router)