Skip to content

Commit 343a82d

Browse files
Fix error message for instant failing jobs. #1132
1 parent 2543fd3 commit 343a82d

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

openeogeotrellis/integrations/calrissian.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,11 @@ def launch_job_and_wait(
415415
elif final_status is None:
416416
raise TimeoutError(f"CWL Job {job_name} did not finish within {timeout}s")
417417
elif final_status != "complete":
418+
messages = ""
419+
if job.status.conditions:
420+
messages = f" Messages: {set(c.message for c in job.status.conditions)}."
418421
raise RuntimeError(
419-
f"CWL Job {job_name} failed with {final_status=} after {timer.elapsed()=:.2f}s. Messages: {set(c.message for c in job.status.conditions)}"
422+
f"CWL Job {job_name} failed with {final_status=} after {timer.elapsed()=:.2f}s.{messages}"
420423
)
421424
else:
422425
raise ValueError("CWL")

tests/integrations/test_calrissian.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from pathlib import Path
23
from typing import Dict, Iterator
34
from unittest import mock
@@ -275,13 +276,21 @@ def create_namespaced_job(self, namespace: str, body: kubernetes.client.V1Job):
275276
def read_namespaced_job(self, name: str, namespace: str):
276277
assert name in self.jobs
277278
assert self.jobs[name].metadata.namespace == namespace
278-
return kubernetes.client.V1Job(
279-
metadata=self.jobs[name].metadata,
280-
status=kubernetes.client.V1JobStatus(
281-
# TODO: way to specify timeline of job conditions?
282-
conditions=[kubernetes.client.V1JobCondition(type="Complete", status="True")]
283-
),
284-
)
279+
if "instant-fail" in name:
280+
return kubernetes.client.V1Job(
281+
metadata=self.jobs[name].metadata,
282+
status=kubernetes.client.V1JobStatus(
283+
failed=1,
284+
),
285+
)
286+
else:
287+
return kubernetes.client.V1Job(
288+
metadata=self.jobs[name].metadata,
289+
status=kubernetes.client.V1JobStatus(
290+
# TODO: way to specify timeline of job conditions?
291+
conditions=[kubernetes.client.V1JobCondition(type="Complete", status="True")]
292+
),
293+
)
285294

286295
with mock.patch("kubernetes.client.BatchV1Api", new=BatchV1Api):
287296
yield
@@ -296,6 +305,14 @@ def test_launch_job_and_wait_basic(self, k8s_batch_api, caplog):
296305

297306
assert caplog.messages[-1] == dirty_equals.IsStr(regex=".*job_name='cal-123'.*final_status='complete'.*")
298307

308+
def test_launch_job_and_wait_fail(self, k8s_batch_api, caplog):
309+
launcher = CalrissianJobLauncher(namespace=self.NAMESPACE, name_base="r-456")
310+
job_manifest = kubernetes.client.V1Job(
311+
metadata=kubernetes.client.V1ObjectMeta(name="cal-123-instant-fail", namespace=self.NAMESPACE)
312+
)
313+
with pytest.raises(RuntimeError, match=re.compile(r"CWL Job.*")) as e_info:
314+
launcher.launch_job_and_wait(manifest=job_manifest)
315+
299316
def test_run_cwl_workflow_basic(
300317
self, k8_pvc_api, k8s_batch_api, generate_unique_id_mock, caplog, s3_calrissian_bucket
301318
):

0 commit comments

Comments
 (0)