Jørgen Nygaard
11/25/2024, 7:08 PMMarvin
11/25/2024, 7:09 PMwait_for
parameter, which you pass to the .submit()
method. This approach ensures that a task will only start executing once the tasks it depends on have completed.
Here's a simplified example based on Prefect 2.x:
python
from prefect import flow, task
@task
def extract_flow():
pass
@task
def transform_flow():
pass
@task
def load_flow():
pass
@flow
def main_flow():
extract_result = extract_flow.submit()
# transform_flow depends on the completion of extract_flow
transform_result = transform_flow.submit(wait_for=[extract_result])
# load_flow depends on the completion of transform_flow
load_result = load_flow.submit(wait_for=[transform_result])
In this example:
- transform_flow
waits for extract_flow
to complete before starting.
- load_flow
waits for transform_flow
to complete before starting.
For more comprehensive details on specifying task dependencies in Prefect 2.x, you can follow this guide: Specifying Upstream Dependencies in Prefect 2.x
While Prefect 3.x offers additional features like transactional semantics, these are generally more advanced and might not be necessary for the straightforward task dependency management you're looking to implement.
Feel free to ask if you have more queries or if I can help you in another way!Jørgen Nygaard
11/25/2024, 7:11 PMMarvin
11/25/2024, 7:11 PM