Skip to content

Commit 5e4e824

Browse files
committed
feat(pulser): better handling during failed job
1 parent 1d95d98 commit 5e4e824

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

pulser_scaleway/scaleway_service.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ def submit(
133133
while any(
134134
job.status in ["waiting", "running"]
135135
for job in self._client.list_jobs(session_id=batch_id)
136-
):
136+
) and self._client.get_session(session_id=batch_id).status in [
137+
"starting",
138+
"running",
139+
]:
137140
time.sleep(_DEFAULT_FETCH_INTERVAL)
138141

139142
if not open:
@@ -162,7 +165,7 @@ def _get_job_result_data(self, job_result: QaaSJobResult) -> str:
162165
if url is not None:
163166
return self._get_data(url)
164167
else:
165-
raise Exception("Got result with empty data and url fields")
168+
raise RuntimeError("Got result with empty data and url fields")
166169
else:
167170
return result
168171

@@ -260,16 +263,25 @@ def _query_job_progress(
260263

261264
def _get_batch_status(self, batch_id: str) -> BatchStatus:
262265
"""Gets the status of a batch from its ID."""
266+
jobs = self._client.list_jobs(session_id=batch_id)
267+
268+
error_in_jobs = any(
269+
job.status in ["cancelled", "cancelling", "error"] for job in jobs
270+
)
271+
272+
if error_in_jobs:
273+
return BatchStatus.ERROR
274+
263275
session = self._client.get_session(session_id=batch_id)
264276

265-
status_mapping = {
277+
session_status_mapping = {
266278
"starting": BatchStatus.PENDING,
267279
"running": BatchStatus.RUNNING,
268280
"stopping": BatchStatus.DONE,
269281
"stopped": BatchStatus.DONE,
270282
}
271283

272-
return status_mapping.get(session.status, BatchStatus.ERROR)
284+
return session_status_mapping.get(session.status, BatchStatus.ERROR)
273285

274286
def _get_job_ids(self, batch_id: str) -> List[str]:
275287
"""Gets all the job IDs within a batch."""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
setup(
2424
name="pulser_scaleway",
25-
version="0.1.4",
25+
version="0.1.5",
2626
project_urls={
2727
"Documentation": "https://www.scaleway.com/en/quantum-as-a-service/",
2828
"Source": "https://github.com/scaleway/pulser-scaleway",

0 commit comments

Comments
 (0)