exit returns 3 things, if the internal work was succesfull these things are None, so you can add a clause in the exit to check for None. For instance if you want to commit database transactions only on success
this does not actually work because dagster wraps everything up to continue executing.
Is there a way to signal to a resource that an OP was successful? Usecase: I want to commit a database transaction on resource teardown, but ONLY if the op was successful. I have looked into dagster_run object that is available through context, but the failure event happens after teardown.
hi Nick, yes normally that would be a great solution. But can I access the same things inside the resource?
looking at the source code the hook looks at events in the context
could I access the events from the resource?
n
nickvazz
11/18/2022, 5:02 PM
Oh that is an interesting question, I did not see the rest of the thread and have not tried using the
@success_hook
with a resource before
c
claire
11/18/2022, 11:30 PM
Hi Roel. Not sure if this is what you are asking, but since a hook executes in the same process as the step it is attached to, you'll be able to access/write to a resource within an op and then access the same instance of the resource in the hook that executes after the op
r
Roel Hogervorst
11/24/2022, 7:17 AM
Hi @claire, thank you ! My team and I have come to the conclusion that although it would be technically possible to create a database commit at success of an op, the way to do this is way too complex. It is much simpler and debuggable to do it inside the op and without the :magic: magic of hooks and resources combined. If it feels like i'm fighting the dagster system than this is a strong signal that we are trying to solve the problem at the wrong level 🤔