https://dagster.io/ logo
#ask-community
Title
# ask-community
r

Ryan Riopelle

08/12/2022, 8:23 PM
Sorta dumb simple question here. I am converting a bunch of classes to dagster jobs and ops. I have some classes that instantiate a bunch of variables as part of the init in the class, and then functions manipulate the vars as it loops through the functions eventually getting to a final output before updating a database. So for example one function might run 100 times and return self.var +=1, so the class variable would be 100 after running. Is there an easy way to convert something like that between ops? Should I put these vars in to the context, or use a chart. What is a good way to achieve this?
c

claire

08/12/2022, 8:29 PM
Hi Ryan! I think this sounds like a good use case for resources: https://docs.dagster.io/concepts/resources#defining-a-resource You can define a class that contains your variables to be a resource, and in each op, you can do
context.resources.<resource_name>
to modify these variables.
r

Ryan Riopelle

08/12/2022, 8:32 PM
O ok, I was literally just writing some tests to see if that would work. So resources are not just for database connections, and static variables.
Thanks
c

claire

08/12/2022, 8:35 PM
Yes, that's right, resources are an abstraction to reuse some existing object in multiple places within a job or repository