forked from CodeGram-team/CodeGram-BE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (33 loc) · 1.06 KB
/
main.py
File metadata and controls
39 lines (33 loc) · 1.06 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
import uvicorn
from fastapi import FastAPI
from contextlib import asynccontextmanager
from db.mongodb import init_db, close_connection
from db.rmq import rmq_client
from api.v1.auth import oauth_router
from api.v1.execution import execution_router
from api.v1.post import post_router
from api.v1.challenge import challenge_router
from api.v1.profile import profile_router
async def start():
await init_db()
await rmq_client.connect()
print("Application startup complete")
async def shutdown():
await close_connection()
await rmq_client.close()
print("Application shutdown")
@asynccontextmanager
async def lifespan(app:FastAPI):
await start()
yield
await shutdown()
app = FastAPI(title="CodeGram API",
description="API for CodeGram Service",
lifespan=lifespan)
app.include_router(oauth_router)
app.include_router(execution_router)
app.include_router(post_router)
app.include_router(challenge_router)
app.include_router(profile_router)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)