Idan
07/24/2023, 10:16 AMon_failure
and on_cancellation
dynamically via the SDK?Jan Malek
07/24/2023, 10:45 AMFlow.with_options(on_failure=[<foo>], on_cancellation=[<bar>])
could work? Depends on what you're trying to do I guess.Idan
07/24/2023, 10:48 AMdef cleanup(foo, bar):
# do stuff with foo and bar
@prefect.flow(name=...)
def the_flow():
# do stuff
a = ...
b = ...
# here I'd like to be able to do smth like the following
this_flow.on_cancellation = lambda: cleanup(a, b)
Jan Malek
07/24/2023, 10:50 AMIdan
07/24/2023, 10:50 AMJan Malek
07/24/2023, 10:52 AMcleanup_callbacks = []
def cleanup():
for cleaner in cleanup_callbacks:
cleaner()
@flow(on_cancellation=cleanup)
def some_func(*args, **kwargs):
...
a = foo()
cleanup_callbacks.append(lambda: cleanup_a)
Idan
07/24/2023, 10:54 AMon_cancellation
argument is new, and we’ve pinned prefect to some previous version. In older versions, would on_failure
also trigger for cancellation and crashes?Jan Malek
07/24/2023, 10:56 AMcontextlib.ExitStack
Idan
07/24/2023, 10:56 AMdef cleanup
in your example above require the additional arguments Prefect expects? Or are those optional?)Jan Malek
07/24/2023, 10:57 AMIdan
07/24/2023, 10:58 AMJan Malek
07/24/2023, 10:58 AMIdan
07/24/2023, 11:04 AMon_failure
was literally only for the failed state. Would you know if these server-side triggers also result in some internal exceptions that can be caught?atexit
would work 😛