Skip to content

Commit 8c8ff7c

Browse files
committed
fix(tangle-cli): defer submit failure hooks during recovery
Assisted-By: devx/0c001c3a-79d6-4fd4-9ba8-4012e253d1e2
1 parent 6307c62 commit 8c8ff7c

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

packages/tangle-cli/src/tangle_cli/pipeline_run_manager.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,7 @@ def submit_prepared_body(
10491049
pipeline_path: str | Path | None = None,
10501050
attempt: int = 1,
10511051
context: PipelineRunContext | None = None,
1052+
notify_submit_error: bool = True,
10521053
) -> dict[str, Any]:
10531054
self.normalize_submit_body_in_place(body)
10541055
pipeline_spec = body["root_task"]["componentRef"]["spec"]
@@ -1068,7 +1069,8 @@ def submit_prepared_body(
10681069
try:
10691070
response = self.to_plain(client.pipeline_runs_create(body=body))
10701071
except Exception as exc:
1071-
self.hooks.on_submit_error(exc, context=submit_context)
1072+
if notify_submit_error:
1073+
self.hooks.on_submit_error(exc, context=submit_context)
10721074
raise
10731075
if not isinstance(response, dict):
10741076
response = {}
@@ -1737,6 +1739,7 @@ def _run_body_factory(
17371739
pipeline_path=pipeline_path,
17381740
attempt=attempt,
17391741
context=context,
1742+
notify_submit_error=False,
17401743
)
17411744
except Exception as submit_exc:
17421745
if context.run_id is not None:
@@ -1751,6 +1754,7 @@ def _run_body_factory(
17511754
submission_id=submission_id_for_recovery,
17521755
)
17531756
if recovered_response is None:
1757+
self.hooks.on_submit_error(submit_exc, context=context)
17541758
raise
17551759
response = self._adopt_submitted_run(
17561760
response=recovered_response,

tests/test_pipeline_runs_cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,11 @@ class DynamicTimeHooks(PipelineRunnerHooks):
16791679
def __init__(self) -> None:
16801680
super().__init__()
16811681
self.prepare_run_arguments_calls = 0
1682+
self.submit_errors: list[str] = []
1683+
1684+
def on_submit_error(self, error, *, context):
1685+
del context
1686+
self.submit_errors.append(str(error))
16821687

16831688
def read_pipeline_yaml(self, pipeline_path):
16841689
return {
@@ -1720,6 +1725,7 @@ def pipeline_runs_list(self, **kwargs: Any) -> dict[str, Any]:
17201725
assert result["context"].root_execution_id == "exec-created"
17211726
assert result["context"].metadata["recovered_after_submit_error"] is True
17221727
assert hooks.prepare_run_arguments_calls == 1
1728+
assert hooks.submit_errors == []
17231729
assert len(client.created) == 1
17241730
submission_id = client.created[0]["annotations"]["tangle-cli/submission-id"]
17251731
assert submission_id
@@ -1739,6 +1745,11 @@ class DynamicTimeHooks(PipelineRunnerHooks):
17391745
def __init__(self) -> None:
17401746
super().__init__()
17411747
self.prepare_run_arguments_calls = 0
1748+
self.submit_errors: list[str] = []
1749+
1750+
def on_submit_error(self, error, *, context):
1751+
del context
1752+
self.submit_errors.append(str(error))
17421753

17431754
def read_pipeline_yaml(self, pipeline_path):
17441755
return {
@@ -1779,6 +1790,7 @@ def pipeline_runs_list(self, **kwargs: Any) -> dict[str, Any]:
17791790

17801791
assert result["response"]["id"] == "run-2"
17811792
assert hooks.prepare_run_arguments_calls == 1
1793+
assert hooks.submit_errors == ["submit timed out"]
17821794
assert [body["root_task"]["arguments"]["exec_time"] for body in client.created] == ["time-1", "time-1"]
17831795
assert [body["root_task"]["componentRef"]["spec"]["name"] for body in client.created] == [
17841796
"run-time-1",

0 commit comments

Comments
 (0)