Skip to content

Commit 82ea1b5

Browse files
committed
Merge remote-tracking branch 'materialsproject/main' into uuid_patch
2 parents 923468b + 9bd99a8 commit 82ea1b5

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/jobflow/managers/local.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def run_locally(
2121
root_dir: str | Path | None = None,
2222
ensure_success: bool = False,
2323
allow_external_references: bool = False,
24+
raise_immediately: bool = False,
2425
) -> dict[str, dict[int, jobflow.Response]]:
2526
"""
2627
Run a :obj:`Job` or :obj:`Flow` locally.
@@ -46,6 +47,10 @@ def run_locally(
4647
allow_external_references : bool
4748
If False all the references to other outputs should be from other Jobs
4849
of the Flow.
50+
raise_immediately : bool
51+
If True, raise an exception immediately if a job fails. If False, continue
52+
running the flow and only raise an exception at the end if the flow did not
53+
finish running successfully.
4954
5055
Returns
5156
-------
@@ -102,14 +107,19 @@ def _run_job(job: jobflow.Job, parents):
102107
errored.add(job.uuid)
103108
return None, False
104109

105-
try:
110+
if raise_immediately:
106111
response = job.run(store=store)
107-
except Exception:
108-
import traceback
109-
110-
logger.info(f"{job.name} failed with exception:\n{traceback.format_exc()}")
111-
errored.add(job.uuid)
112-
return None, False
112+
else:
113+
try:
114+
response = job.run(store=store)
115+
except Exception:
116+
import traceback
117+
118+
logger.info(
119+
f"{job.name} failed with exception:\n{traceback.format_exc()}"
120+
)
121+
errored.add(job.uuid)
122+
return None, False
113123

114124
responses[job.uuid][job.index] = response
115125

tests/managers/test_local.py

+3
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ def test_error_flow(memory_jobstore, clean_dir, error_flow, capsys):
331331
with pytest.raises(RuntimeError):
332332
run_locally(flow, store=memory_jobstore, ensure_success=True)
333333

334+
with pytest.raises(ValueError, match="errored"):
335+
run_locally(flow, store=memory_jobstore, raise_immediately=True)
336+
334337

335338
def test_ensure_success_with_replace(memory_jobstore, error_replace_flow, capsys):
336339
from jobflow import run_locally

0 commit comments

Comments
 (0)