-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·55 lines (39 loc) · 1.14 KB
/
main.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
52
53
54
55
#!/usr/bin/env python3
import atexit
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
import uvicorn
from fastapi import FastAPI
import app.clients
import app.exception_handling
import app.logging
from app import settings
from app.api.webhooks import webhooks_router
@asynccontextmanager
async def lifespan(asgi_app: FastAPI) -> AsyncIterator[None]:
try:
await app.clients.database.connect()
yield
finally:
await app.clients.database.disconnect()
asgi_app = FastAPI(lifespan=lifespan)
@asgi_app.get("/_health")
async def health():
return {"status": "ok"}
asgi_app.include_router(webhooks_router)
def main() -> int:
app.logging.configure_logging()
app.exception_handling.hook_exception_handlers()
atexit.register(app.exception_handling.unhook_exception_handlers)
uvicorn.run(
"main:asgi_app",
reload=settings.CODE_HOTRELOAD,
server_header=False,
date_header=False,
host=settings.APP_HOST,
port=settings.APP_PORT,
access_log=False,
)
return 0
if __name__ == "__main__":
raise SystemExit(main())