Can a state handler launch another prefect task? M...
# prefect-community
k
Can a state handler launch another prefect task? My end goal is to handle failed tasks via another task. Right now I've implemented everything in a state handler, but I don't get Prefect logging/tracking like I do with a task.
k
Hey @Kyle McEntush, I think the best way to approach this is to use triggers to initialize downstream tasks based on final task states. You can also use this in combination with signals as you mentioned earlier for specific conditions of that task. With this, you'll be able to launch other tasks conditionally based on those states and set up your flow context without state handlers.
k
I see. The task that may fail is a mapped task, and I want to trigger the fail-handling task for each of the failed. I'm not sure which trigger would be ideal
It seems like "any" may be the ideal one, but i'm not sure how that applies in a mapped task case
k
Yeah, I'd say
any_failed
is your best option but I encourage you to experiment. Also just as a reminder to be conscientious of state behavior with mapped tasks - trigger functions will be applied to all mapped children and not the parent.