https://prefect.io logo
#prefect-community
Title
# prefect-community
j

Jason

05/04/2022, 2:50 PM
When using classes with @tasks, I'm assuming that the class needs to be instantiated each time for each task? For example:
Copy code
@task
def task_a():
    common_class = Common(Secret())
    output = common_class.task_a()
    return output

@task
def task_b():
    common_class = Common(Secret())
    output = common_class.task_b()
    return output
k

Kevin Kho

05/04/2022, 2:52 PM
I don’t think so. It would just get serialized along with the task. Do you get an error?
a

Anna Geller

05/04/2022, 3:56 PM
also, are you asking because of Prefect Secrets?
j

Jason

05/04/2022, 4:01 PM
Yeah, I think I've figured out the class error. I have an API abstraction module that I'd like to use across the tasks, and it takes in a token and secret, so I was curious about the best practice. I like to use class organization instead of using many different methods when possible.
a

Anna Geller

05/04/2022, 4:18 PM
Gotcha. You can definitely combine functional tasks with your custom classes. Many users use
PrefectSecret
tasks in their flows and pass the value of the secret to a downstream task (which may use classes inside that receive the input data from a task) - this would allow you to get the best of both worlds. LMK if you need an example
👍 1
5 Views