https://prefect.io logo
Title
r

Richard Alexander

10/25/2022, 2:43 PM
I am on Prefect 2.6.4 and have a question about "immediate scheduling". I have many tasks that run on a schedule, but now I have a need for a more event-driven flow run. Specifically, I need to immediately schedule a flow run from a script, but I need the call from the script to return immediately (rather than holding up the script and waiting for the flow to complete). I'm sure the answer is simple, but I'm not familiar with this pattern in Prefect 2 and can't find a reference to it in the docs or API. Thanks for the help! :-)
1
o

Oscar Björhn

10/25/2022, 2:51 PM
Have a look at the new run_deployment function added around 2.5.x (if I recall correctly), should do what you need!
:gratitude-thank-you: 2
🙌 2
r

Richard Alexander

10/25/2022, 8:54 PM
Thanks for the help @Oscar Björhn and @Anna Geller. I've been testing
run_deployment
today, but it doesn't seem to work as expected. While I can start a flow run via a script, it blocks the rest of the script from running until the entire flow is completed. Is that the expected behavior? Am I missing some flag that needs to be set in order for
run_deployment
to return immediately?
I'm running Prefect locally... I don't know if that makes any difference.
o

Oscar Björhn

10/25/2022, 10:31 PM
Sorry about that. There's a parameter you can set when calling the function to make it work called "timeout". "The amount of time to wait for the flow run to complete before returning. Setting
timeout
to 0 will return the flow run immediately."
:gratitude-thank-you: 1
👍 1
Setting it to 0 will essentially result in a decoupled, "async" (my terminology to explain the concept, not Prefect's 😛) flow run.
:gratitude-thank-you: 1
a

Anna Geller

10/25/2022, 11:08 PM
Oscar's explanation is great but also check out the docstring of run_deployment, timeout should let you define exactly the behavior you want @Richard Alexander
r

Richard Alexander

10/26/2022, 1:27 PM
YES! That did it. Thanks so much Anna and Oscar! For anyone coming across this thread, here are the run_deployment docs.
🙌 2