Hi everyone, I am just getting started with prefect and am struggling with what is probably a very basic concept. Is it possible to use a @task decorator with tasks from the task library? My primary use case is orchestrating dbt jobs and I would like to add a state handler for my tests to send a notification on task failure.
k
Kevin Kho
12/28/2021, 9:51 PM
Hey @Chris McLaughlin, no worries! You don’t need a task decorator with those.
Copy code
from prefect.tasks... import SomeTask
some = SomeTask(state_handlers=[mystatehandler])
with Flow(..) as flow:
some(x=1, y=2)
c
Chris McLaughlin
12/28/2021, 9:52 PM
Ah, way easier than I thought! I'm assuming you could define a trigger in the same manner?
k
Kevin Kho
12/28/2021, 9:54 PM
Yes the tasks in the task library take in the same arguments as
@task()
. If your task has inputs, you can still stick them in there.
Copy code
some = SomeTask(x=1, y=2, state_handlers=[mystatehandler], triggers=...)
with Flow(...) as flow:
some()
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.