| 123456789101112131415161718192021222324252627282930313233 |
- from fastapi import FastAPI
- from pydantic import BaseModel
- from celery.result import AsyncResult
- app = FastAPI()
- from tasks import process_data
- class Task(BaseModel):
- bianma: str
- mc: str
- tz: str
- dw: str
- sl: str
- n: int
- label: str
- name: str
- bh: str
- city: str
- @app.post("/submit/")
- async def submit(r: Task):
- task = process_data.apply_async(kwargs={"data": { "city" : r.city, "bianma": r.bianma, "mc": r.mc, "tz": r.tz, "dw": r.dw, "sl": r.sl, "n": r.n, "label": r.label, 'name': r.name, 'bh': r.bh}})
- return {"id": task.id}
- @app.get("/check/{id}")
- async def check(id):
- result = AsyncResult(id)
- return {
- 'status': result.status,
- 'result': result.result if result.ready() else None
- }
|