forked from sumanentc/fastapi-celery-rabbitmq-application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
36 lines (25 loc) · 1.03 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
import time
import uvicorn as uvicorn
from fastapi import FastAPI
from config.celery_utils import create_celery
from routers import universities
def create_app() -> FastAPI:
current_app = FastAPI(title="Asynchronous tasks processing with Celery and RabbitMQ",
description="Sample FastAPI Application to demonstrate Event "
"driven architecture with Celery and RabbitMQ",
version="1.0.0", )
current_app.celery_app = create_celery()
current_app.include_router(universities.router)
return current_app
app = create_app()
celery = app.celery_app
@app.middleware("http")
async def add_process_time_header(request, call_next):
print('inside middleware!')
start_time = time.time()
response = await call_next(request)
process_time = time.time() - start_time
response.headers["X-Process-Time"] = str(f'{process_time:0.4f} sec')
return response
if __name__ == "__main__":
uvicorn.run("main:app", port=9000, reload=True)