-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
46 lines (35 loc) · 864 Bytes
/
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
import asyncio
import os
from logging import getLogger
import uvicorn
from fastapi import FastAPI
from src.app import get_app
from src.config import Config
logger = getLogger(__name__)
def get_server(app: FastAPI, config: Config):
server = uvicorn.Server(
config=uvicorn.Config(
app=app,
host="0.0.0.0",
port=config.PORT,
)
)
return server
async def run_server():
config = Config() # type: ignore[call-arg]
app = get_app(config=config)
server = get_server(app=app, config=config)
await server.serve()
def main():
try:
asyncio.run(run_server())
except (
SystemExit,
KeyboardInterrupt,
):
exit(os.EX_OK)
except Exception as error:
logger.error(error)
exit(os.EX_SOFTWARE)
if __name__ == "__main__":
main()