Thread
#prefect-community
    Danny Vilela

    Danny Vilela

    9 months ago
    Hi! I have a
    @task
    -decorated function with
    max_retries=8, retry_delay=dt.timedelta(minutes=15)
    . However, I know that for certain kinds of errors, I’d actually want it to wait 30 minutes (or even an hour). Is there a way to implement this? I know I can probably just check for that exception then
    time.sleep
    for the extra time (for example, to wait for an hour I’d catch the exception,
    time.sleep
    for 45 minutes, then raise the error so that
    retry_delay
    kicks in), but I’m wondering if there’s a cleaner way to approach this. The above feels like a code smell but I’m not sure how I’d otherwise set context-specific retry delays on a task 🤔
    Anna Geller

    Anna Geller

    9 months ago
    You’re 100% correct that there is no straightforward way to configure it atm. Another user asked about a variable number of retries and here is a hacky solution I came up with. It will be easier in Orion, but for now you need a workaround e.g. using the KV Store.
    Kevin Kho

    Kevin Kho

    9 months ago
    I think this can be done inside the state handler. If you have an error, you can access it with
    type(new_state.result)
    I think. And then you can put another
    time.sleep
    in the state handler depending on the error type.