Skip to content

Commit

Permalink
Handle case in _get_progress where map runs haven't started yet
Browse files Browse the repository at this point in the history
If we're still in pre-processing, the map runs haven't started yet, so
we need to deal with case where there are no map run entries yet, else
there will be an exception/Internal Server Error
  • Loading branch information
danscales committed Aug 19, 2024
1 parent ae83db0 commit 13cb2a2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/routes/jobs/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,18 @@ async def _get_sfn_execution(job_id: UUID) -> Dict[str, Any]:

async def _get_progress(execution: Dict[str, Any]) -> str:
map_run = await _get_map_run(execution)
if len(map_run) == 0:
# No map runs have started yet
return "0%"
success_ratio = map_run["itemCounts"]["succeeded"] / map_run["itemCounts"]["total"]
return f"{round(success_ratio * 100)}%"


async def _get_map_run(execution: Dict[str, Any]) -> Dict[str, Any]:
map_runs = get_sfn_client().list_map_runs(executionArn=execution["executionArn"])
map_run_arn = map_runs["mapRuns"][0]["mapRunArn"]
map_runs = get_sfn_client().list_map_runs(executionArn=execution["executionArn"])["mapRuns"]
if len(map_runs) == 0:
# No map runs have started yet, return empty dict
return {}
map_run_arn = map_runs[0]["mapRunArn"]
map_run = get_sfn_client().describe_map_run(mapRunArn=map_run_arn)
return map_run

0 comments on commit 13cb2a2

Please sign in to comment.