wip add a status endpoint

This commit is contained in:
lebaudantoine
2024-11-29 17:51:44 +01:00
parent 5c84dbff88
commit f99312f12b
+10 -2
View File
@@ -1,5 +1,6 @@
"""Application endpoint."""
from celery.result import AsyncResult
from fastapi import Depends, FastAPI
from pydantic import BaseModel
@@ -32,5 +33,12 @@ class NotificationRequest(BaseModel):
@app.post("/push")
async def notify(request: NotificationRequest, token: str = Depends(verify_token)):
"""Push a notification."""
send_push_notification.delay(request.filename, request.email, request.sub)
return {"message": "Notification sent"}
task = send_push_notification.delay(request.filename, request.email, request.sub)
return {"task_id": task.id, "message": "Notification sent"}
@app.get("/status/{task_id}")
async def get_status(task_id: str, token: str = Depends(verify_token)):
"""Check task status by ID."""
task = AsyncResult(task_id)
return {"task_id": task_id, "status": task.status}