Skip to content

Commit

Permalink
fix: downloading data extract accessing download_url key
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Feb 1, 2024
1 parent f0ea999 commit f48bbd9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,19 +662,26 @@ async def get_data_extract_url(
log.error(f"Failed to get extract from raw data api: {error_dict}")
return error_dict

task_id = result.json()["task_id"]
task_id = result.json().get("task_id")

# Check status of task (PENDING, or SUCCESS)
task_url = f"{base_url}/tasks/status/{task_id}"
while True:
result = requests.get(task_url, headers=headers)
if result.json()["status"] == "PENDING":
if result.json().get("status") == "PENDING":
# Wait 2 seconds before polling again
time.sleep(2)
elif result.json()["status"] == "SUCCESS":
elif result.json().get("status") == "SUCCESS":
break

fgb_url = result.json()["result"]["download_url"]
fgb_url = result.json().get("result", {}).get("download_url", None)

if not fgb_url:
raise HTTPException(
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
detail="Could not get download URL for data extract. Did the API change?",
)

return fgb_url


Expand Down

0 comments on commit f48bbd9

Please sign in to comment.