I have a use case where I need to use multiple res...
# prefect-community
j
I have a use case where I need to use multiple resource managers in a flow which cannot co-exist for reasons beyond my control. Is there a way to have a resource manager's initialization await an upstream task?
c
Hi Justin - yes there are a few ways; if you are using the context manager, the returned object is the
setup
task which you can then call the various task methods on:
Copy code
with MyResource(...) as resource:
     resource.set_upstream(other_task)
It sounds like you want to create a dependency on the init task, which you can do by accessing this task as an attribute of the resource object:
Copy code
my_resource = MyResource(...)
my_resource.init_task.set_upstream(other_task)

with my_resource:
    ...
j
Thank you! That worked but I ran into a snag later where I dont have an intermediate task to set as an upstream. Is there a way to set the cleanup task of the previous resource manager as the upstream? I can insert a do-nothing task to get there but that feels wonky.
c
yup yup:
Copy code
first_resource = FirstResource(...)
second_resource = SecondResource(...)

second_resource.init_task.set_upstream(first_resource.cleanup_task)
j
ah okay, but not with the context manager i guess?
c
you can still use the context managers:
Copy code
with first_resource as resource:
    ... 

with second_resource as another_resource:
    ...
j
oh duh, obviously. ty so much 😄
c
anytime!
@Marvin archive “How to set dependencies on Resource Managers”