Hi all, a couple questions about state handlers.
1. I want to run a function f() when a task finishes successfully on retry. In other words, a task goes from failure —> retrying —> running —> success. How can I capture that scenario in a state handler if I only have new_state and old_state?
2. Where can I find a task’s start and end time from within a state handler? For context, I want a state handler to log this information in the event of a task failure.
Thanks so much!
k
Kevin Kho
10/01/2021, 7:49 PM
Hey @Matthew Seligson, you can pull some things from the context that can help you with number 1. I am thinking you can use the condition in
task_run_count
.
I don’t think you can get end time because that doesn’t exist yet until the state handler is done. For start time…it may have to be taken from the GraphQL API. I think for end time, using
Thanks so much @Kevin Kho, and sorry for the slow response. Regarding the start time, how can I open a feature request to add task start time to the task object or prefect context?
k
Kevin Kho
10/06/2021, 2:58 PM
I honestly don’t think we’d add it. The context is currently copied a couple of times in a Flow run so everything added has the potential to bloat it. So we only have the most common things available + the things needed to actually run the task
u
张强
10/10/2021, 12:16 AM
ƒcelery
k
Kevin Kho
10/10/2021, 4:05 AM
Oh you can still open a feature request for this @Matthew Seligson, we can see what the core team says
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.