Skip to content

Commit

Permalink
feat(api): fix
Browse files Browse the repository at this point in the history
  • Loading branch information
salemsd committed Dec 16, 2024
1 parent 2922b2e commit 477557d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/antares/exceptions/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,6 @@ def __init__(self, study_id: str, job_id: str, message: str) -> None:


class SimulationFailedError(Exception):
def __init__(self, study_id: str) -> None:
self.message = f"Simulation failed for {study_id}"
def __init__(self, study_id: str, job_id: str) -> None:
self.message = f"Simulation failed for {study_id} and job {job_id}"
super().__init__(self.message)
12 changes: 5 additions & 7 deletions src/antares/service/api_services/run_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _get_job_from_id(self, job_id: str, parameters: AntaresSimulationParameters)
response = self._wrapper.get(url)
job_info = response.json()
status = JobStatus.from_str(job_info["status"])
output_id = job_info["output_id"] if status == JobStatus.SUCCESS else None
output_id = job_info.get("output_id")
return Job(job_id=job_id, status=status, parameters=parameters, output_id=output_id)

def wait_job_completion(self, job: Job, time_out: int) -> None:
Expand All @@ -71,13 +71,13 @@ def wait_job_completion(self, job: Job, time_out: int) -> None:
self._update_job(job)

if job.status == JobStatus.FAILED or not job.output_id:
raise SimulationFailedError(self.study_id)
raise SimulationFailedError(self.study_id, job.job_id)

if job.parameters.unzip_output:
try:
self._wait_unzip_output(self.study_id, job, time_out)
except (TaskFailedError, AntaresSimulationUnzipError) as e:
raise SimulationFailedError(self.study_id) from e
except AntaresSimulationUnzipError as e:
raise SimulationFailedError(self.study_id, job.job_id) from e

return None

Expand All @@ -95,10 +95,8 @@ def _wait_unzip_output(self, ref_id: str, job: Job, time_out: int) -> None:
tasks = response.json()
task_id = self._get_unarchiving_task_id(job, tasks)
self._wait_task_completion(task_id, repeat_interval, time_out)
except APIError as e:
except (APIError, TaskFailedError) as e:
raise AntaresSimulationUnzipError(self.study_id, job.job_id, e.message) from e
except TaskFailedError as e:
raise e

def _get_unarchiving_task_id(self, job: Job, tasks: list[dict[str, Any]]) -> str:
for task in tasks:
Expand Down

0 comments on commit 477557d

Please sign in to comment.