Skip to content

Commit

Permalink
chore: small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
elisalimli committed Mar 12, 2024
1 parent ecf6d04 commit d12b73e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions api/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,29 @@ async def get_task(

task_manager = IngestTaskManager(redis_client)

def handle_task_not_found(task_id: str):
logger.warning(f"Task {task_id} not found")
return JSONResponse(
status_code=status.HTTP_404_NOT_FOUND,
content={"success": False, "error": {"message": "Task not found"}},
)

if not long_polling:
task = task_manager.get(task_id)
if not task:
logger.warning(f"Task {task_id} not found")
return JSONResponse(
status_code=status.HTTP_404_NOT_FOUND,
content={"sucess": False, "error": {"message": "Task not found"}},
)

return handle_task_not_found(task_id)
return {"success": True, "task": task.model_dump()}

else:
start_time = time.time()
timeout_time = start_time + 30 # 30 seconds from now
sleep_interval = 3 # seconds

while start_time < timeout_time:
task = task_manager.get(task_id)

if task is None:
handle_task_not_found(task_id)

if task.status != TaskStatus.PENDING:
return {"success": True, "task": task.model_dump()}
await asyncio.sleep(sleep_interval)
Expand Down

0 comments on commit d12b73e

Please sign in to comment.