Skip to content
Advertisement

Looping tasks in Prefect

I want to loop over tasks, again and again, until reaching a certain condition before continuing the rest of the workflow.

What I have so far is this:

JavaScript

But as far as I understand this does not work for multiple tasks. Is there a way to come back further and loop on several tasks at a time ?

Advertisement

Answer

The solution is simply to create a single task that itself creates a new flow with one or more parameters and calls flow.run(). For example:

JavaScript

where print_loop simply prints “loop” in the output and add_value adds one to the value it receives.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement