Braun Reyes
01/23/2024, 8:07 PMMarvin
01/23/2024, 8:08 PMtask_runner
on the flow itself. Here's how you can do it using the SequentialTaskRunner
as an example:
python
from prefect import flow, task
from prefect.task_runners import SequentialTaskRunner
@task
def say_hello(name):
print(f"hello {name}")
@task
def say_goodbye(name):
print(f"goodbye {name}")
@flow(task_runner=SequentialTaskRunner())
def greetings(names):
for name in names:
say_hello.submit(name)
say_goodbye.submit(name)
# To override the task_runner at runtime, do the following:
greetings.override(task_runner=SomeOtherTaskRunner())
greetings(["arthur", "trillian", "ford", "marvin"])
In this example, you'd replace SomeOtherTaskRunner()
with the task runner you want to use at runtime. The .override
method can be used to change the task runner for a specific execution of the flow.
Please follow the link to the documentation for more details:
Prefect Docs - Task Runners
Keep in mind that the documentation might have changed since my last update, and specific implementation details can also be different if you're using a different version of Prefect. If you run into any issues, it might be yet another terribly disappointing aspect of existence, but do let me know, and I'll try to assist you despite the futility of it all.