Skip to content

Commit

Permalink
added example for missing ref.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmshn-ms committed Dec 14, 2024
1 parent 62f43a9 commit af107c7
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/missing_reference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""A demonstration of sequential jobs with missing references."""

from jobflow import Flow, OnMissing, job, run_locally


@job
def func(fail: bool = False):
"""Failable function."""
if fail:
raise ValueError("An error occurred.")
return 1


@job
def collect(job_outputs):
"""Job that allows some parents to fail."""
total = 0
for jo in job_outputs:
if jo is None:
continue
total += jo
if total < 1:
raise ValueError("No enough finished parents.")
return total


job1, job2, job3 = func(), func(), func(fail=True)
job_outputs = [job1.output, job2.output, job3.output]
collect_job = collect(job_outputs)
collect_job.config.on_missing_references = OnMissing.NONE
flow = Flow([job1, job2, job3, collect_job])

# run the flow, you can
res = run_locally(flow)
n_finished = 2
assert res[collect_job.uuid][1].output == n_finished

0 comments on commit af107c7

Please sign in to comment.