-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
33 lines (25 loc) · 945 Bytes
/
Copy pathapp.py
File metadata and controls
33 lines (25 loc) · 945 Bytes
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
from fastapi import FastAPI
from api import router as api_router
from kafka_config import consume_messages
from rabbitmq_config import consume_rabbitmq_messages
from contextlib import asynccontextmanager
@asynccontextmanager
async def LifeSpan(app: FastAPI):
print("-----------------APP STARTED----------------------")
import asyncio
loop = asyncio.get_event_loop()
loop.run_in_executor(None, consume_rabbitmq_messages)
loop.run_in_executor(None, consume_messages)
yield
print("-----------------APP ENDED----------------------")
app = FastAPI(
title="Mail Service",
version="1.0.0",
description="Service for sending emails",
summary="This API provides endpoints for sending emails.",
lifespan=LifeSpan,
)
app.include_router(api_router, prefix="/api", tags=["Mail Service"])
@app.get("/", include_in_schema=False)
async def root():
return {"message": "Welcome to the Mail Service API"}