Adds a retry policy to a Modal function.
import modal stub = modal.Stub() # Basic configuration. # This sets a policy of max 4 retries with 1-second delay between failures. def f(): pass # Fixed-interval retries with 3-second delay between failures. def g(): pass # Exponential backoff, with retry delay doubling after each failure. def h(): pass
def __init__( self, *, # The maximum number of retries that can be made in the presence of failures. max_retries: int, # Coefficent controlling how much the retry delay increases each retry attempt. # A backoff coefficient of 1.0 creates fixed-delay retries where the delay period will always equal the initial delay. backoff_coefficient: float = 2.0, # Number of seconds that must elapse before the first retry occurs. initial_delay: float = 1.0, # Maximum length of retry delay in seconds, preventing the delay from growing infinitely. max_delay: float = 60.0, ):
Construct a new retries policy, supporting exponential and fixed-interval delays via a backoff coefficient.