代码拉取完成,页面将自动刷新
import time
import uvicorn as uvicorn
from fastapi import FastAPI
from config.celery_utils import create_celery
from routers import universities,sherpa
import subprocess
from multiprocessing import Process
import config
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)
current_app.include_router(sherpa.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
def start_celery():
subprocess.run(['celery', '-A', 'main.celery', 'worker', '-l', 'info','-Q',config.get_queues(),'-c','4'])
def start_celery_flower():
subprocess.run(['celery', '-A', 'main.celery', 'flower', '--port=5555'])
if __name__ == "__main__":
celery_process = Process(target=start_celery)
celery_process.start()
celery_flower_process = Process(target=start_celery_flower)
celery_flower_process.start()
uvicorn.run("main:app", port=9000, reload=True)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。