Hi guys, good morning. :slightly_smiling_face: I'm...
# prefect-community
Hi guys, good morning. 🙂 I'm starting to use prefect, and have a quick newbie question: What kind of scenario would I use task class instead of the task decorator? Just trying to understand it better.
⬆️ 1
👋 1
Hi Alex, great question! The task decorator just overrides the
method, so it's good for quick and dirty tasks. If you want to do something more in-depth or customizable, that's generally when you'd want to subclass. Does that make sense?
I've also found this page super useful as a more in-depth view of tasks-- might be helpful! https://docs.prefect.io/core/tutorials/task-guide.html
👍 3
I usually convert my decorated tasks into the task class, if I am passing parameters to the task that are known before the flow begins. For instance my database host address or username aren’t going to change based on what happens on the upstream tasks. By providing these values at the
call, I keep them out of the flow, while still utilizing their values. If I instead provided them with
, they wolud show up as
tasks, creating visual clutter in logs.
I think I see it now. Thanks Emre and Zachary 🙂
Does this mean that the
of a task is executed before the flow actually runs?
Yep! Task initialization, like any object initialization, happens as soon as you call
, doesn’t even need to be in the
. Prefect Tasks
, however, is delayed for execution until
happens and the tasks upstream dependencies are met.
👍 1