https://prefect.io logo
Title
j

Justin Mooney

07/31/2020, 8:10 PM
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

Chris White

07/31/2020, 8:40 PM
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:
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:
my_resource = MyResource(...)
my_resource.init_task.set_upstream(other_task)

with my_resource:
    ...
j

Justin Mooney

07/31/2020, 8:53 PM
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

Chris White

07/31/2020, 8:54 PM
yup yup:
first_resource = FirstResource(...)
second_resource = SecondResource(...)

second_resource.init_task.set_upstream(first_resource.cleanup_task)
j

Justin Mooney

07/31/2020, 8:55 PM
ah okay, but not with the context manager i guess?
c

Chris White

07/31/2020, 8:55 PM
you can still use the context managers:
with first_resource as resource:
    ... 

with second_resource as another_resource:
    ...
j

Justin Mooney

07/31/2020, 8:58 PM
oh duh, obviously. ty so much 😄
c

Chris White

07/31/2020, 8:58 PM
anytime!
@Marvin archive “How to set dependencies on Resource Managers”