Skip to content

Commit

Permalink
Add endpoint to retrieve task info
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosribas committed Jul 18, 2024
1 parent 6029e80 commit a6b9120
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ def fetch_data(request: APIRequest):
return {"task_id": task.id, "data_type": request.data_type}


@app.get("/info/{task_id}")
def get_task_info(task_id: str):
result = fetch_data_from_search_index.AsyncResult(task_id)
if result.state == "PENDING":
raise HTTPException(status_code=404, detail="Task ID not found")

meta = result.info or {}
if result.state == "SUCCESS":
result_meta = result.result or {}
meta.setdefault("query", result_meta.get("query"))
meta.setdefault("hit_count", result_meta.get("hit_count"))
else:
meta.setdefault("query", result.info.get("query"))
meta.setdefault("hit_count", result.info.get("hit_count"))

return {
"task_id": task_id,
"state": result.state,
"meta": meta
}


@app.get("/download/{task_id}/fasta")
def download_fasta(task_id: str):
return download_file(task_id, "fasta")
Expand Down

0 comments on commit a6b9120

Please sign in to comment.