Are `on_completion` and `on_failure` hooks ignore...
# ask-community
s
Are
on_completion
and
on_failure
hooks ignored when a task state is
Cached
? That seems to be the case, but AFAIK there’s no docs (https://github.com/PrefectHQ/prefect/issues/8967)
1
r
I think the answer to your question is yes - the hooks are ignored when a task already has a cached result. Looking in
engine.py
, the
on_completion
and
on_failure
hooks for tasks get called during the task run here. But if there's a cached result for a task, the Prefect API rejects the proposal to transition the task from PENDING -> RUNNING and instead returns the terminal state with the cached result attached. When that happens, the
state.is_running()
check here is false, and block of code with the hook call gets skipped.
s
Thanks very much 🙏 I wish there was a
on_exit
that would run no matter what the end state - but I’ve hacked something together to get around this (to trigger whether a task state is failed/completed/cached)
r
That might be worth opening a GitHub issue for; it sounds like a reasonable feature request.
upvote 1
s
Okay, thanks