# prefect-community

Jeff Brainerd

06/29/2020, 7:38 PM
Hi team, question about retries. Is there a good way to retry a task conditionally? Specifically, I want to retry a task on certain failures (e.g. db deadlocks). My thought was to use a state handler to detect the right situation (easy) but then how would I actually invoke the retry? Maybe return a new
State object? Couldn’t find any doc examples of this and wanted to know if I missed anything obvious before spelunking. Thanks! 🙏

Kyle Moon-Wright

06/29/2020, 7:42 PM
Hey Jeff, This is a really interesting question, let me get some more information on best practices here.
👍 1
Though I love doc spelunking, I think your best bet is to use a RETRY signal in the state handler that initiates whenever this conditional logic is met. Returning a new state object could work, but I think this signal will be cleaner.
P 1

Jeff Brainerd

06/29/2020, 8:14 PM
Love it. Thanks for the quick response!
cc: @asm


06/29/2020, 8:28 PM