Wrapping up a class

Hi, I’m trying to wrap a class with the flow, like this:

class Algorigthm:

   @task
   def do_first(self, something):
      ....
  
   @task
   def do_second(self, something_else):
      ....

   @flow
   def start_flow(self):
      do_first(..)
      do_second(..)

But it asks me to provide “self”, otherwise, if i do provide the object itself, it gives me a recursion error.
would like to get help.

What are you trying to do? A flow must be a function rather than a class method. But you can call that class and all its methods directly from the flow function. Check out the examples in docs.prefect.io

1 Like
class Algorigthm:

   def do_first(self, something):
      ....
  
   def do_second(self, something_else):
      ....

 @flow
 def start_flow():
     obj = Algorigthm()
    obj.do_first(..)
    obj.do_second(..)

This will work. But how to convert do_first class method to a task?

1 Like

You could instantiate the class and call that class method from within a task. Or you could pass the class instance to a task. Lots of ways to accomplish that, easiest would be if you try out those various options and report back if something doesn’t work as expected.