[Prefect 2] Deploy multiple dependent flows with different time schedules

I’m deploying my production workflow on prefect 2. However, there’s one issue that I have yet figured out a (good) solution so I’m truly looking for help here.

Say I want to deploy 3 flows like below but each having different schedules:

@flow
def run_A():
    pass

@flow  
def run_B():
    pass 

@flow 
def run_C():
   a = run_A()
   b = run_B(wait_for=[a])

In other words, flow B depends on A, but might have a very different time schedule.

For example, B is scheduled to run every 10 minutes, and A is scheduled to run every 5 minutes, both from 09:30am onwards. At 10:00am, A and B both get triggered, but A takes time. I hope that B would respect the dependency (i.e. wait until A finishes) then execute B itself. Note once again that A and B are two separate deployments.

My question is - how can I do it in Prefect 2 in Python (no GUI)?

2 Likes

I’m a novice on Prefect, but from what I understood so far, you need to create a deploy so the deploy will specify the execution of your flow on a worker.

You would need to add something like this to your script:

deploy_with_schedule = Deployment.build_from_flow(
name=“flow_with_schedule”,
flow=run_B,
schedule=CronSchedule(cron=“*/10 * * * *”, timezone=‘America/Sao_Paulo’),
)

deploy_with_schedule .apply()

You can check examples and test your syntax on how to write a corn schedule with https://crontab.guru/ the one in the example above specifies running every 10 minutes.

I also have a similar question on the forum needing help BTW.

Thanks for the reply - the real problem though is how to make the run_B flow deployment depend on the successful completion of run_A flow deployment.