11from typing import Any
22
33from arq .jobs import Job as ArqJob
4- from fastapi import APIRouter , Depends
4+ from fastapi import APIRouter , Depends , HTTPException
55
66from ...api .dependencies import rate_limiter_dependency
77from ...core .utils import queue
@@ -24,7 +24,13 @@ async def create_task(message: str) -> dict[str, str]:
2424 dict[str, str]
2525 A dictionary containing the ID of the created task.
2626 """
27- job = await queue .pool .enqueue_job ("sample_background_task" , message ) # type: ignore
27+ if queue .pool is None :
28+ raise HTTPException (status_code = 503 , detail = "Queue is not available" )
29+
30+ job = await queue .pool .enqueue_job ("sample_background_task" , message )
31+ if job is None :
32+ raise HTTPException (status_code = 500 , detail = "Failed to create task" )
33+
2834 return {"id" : job .job_id }
2935
3036
@@ -42,6 +48,11 @@ async def get_task(task_id: str) -> dict[str, Any] | None:
4248 Optional[dict[str, Any]]
4349 A dictionary containing information about the task if found, or None otherwise.
4450 """
51+ if queue .pool is None :
52+ raise HTTPException (status_code = 503 , detail = "Queue is not available" )
53+
4554 job = ArqJob (task_id , queue .pool )
46- job_info : dict = await job .info ()
47- return vars (job_info )
55+ job_info = await job .info ()
56+ if job_info is None :
57+ return None
58+ return job_info .__dict__ if hasattr (job_info , '__dict__' ) else dict (job_info ) if job_info else None
0 commit comments