Steve Gee
02/09/2024, 6:45 PMMarvin
02/09/2024, 6:46 PM@task
decorator from Prefect to it. The parameters of the function are then accessible within the function body as usual. Here's an example of how to define a task with parameters:
python
from prefect import task
@task
def my_task(param1, param2):
# You can now access param1 and param2 within this task
print(f"The parameters are {param1} and {param2}")
When you call my_task
with arguments, Prefect will handle those parameters:
python
my_task_run = my_task.bind(param1="value1", param2="value2")
If you need to customize task definition, you can use optional keyword arguments provided by the @task
decorator according to the Prefect documentation on tasks. Some of these arguments are:
- `name`: An optional name for the task.
- `tags`: An optional set of tags to be associated with runs of this task.
- `cache_key_fn`: An optional callable that generates a string key for task caching.
- `max_retries`: An optional number of times to retry on task run failure.
- `retry_delay`: An optional number of seconds to wait before retrying the task after failure.
Please visit the provided link to the documentation for more details on customizing your tasks.Nate
02/09/2024, 6:46 PM@task(task_run_name="Process {foo}")
def process(foo: str):
pass
Steve Gee
02/09/2024, 6:48 PM@task(value={foo})
def do_something(foo: bool):
pass
Nate
02/09/2024, 6:49 PMvalue
is not a valid kwarg thereSteve Gee
02/09/2024, 6:49 PMSteve Gee
02/09/2024, 6:50 PMNate
02/09/2024, 6:50 PMwith_options
Nate
02/09/2024, 6:51 PM@task
def foo():
pass
new_foo = foo.with_options(refresh_cache=True if condition else False, ...)
new_foo()
Steve Gee
02/09/2024, 6:51 PMSteve Gee
02/09/2024, 6:51 PMNate
02/09/2024, 6:51 PM