https://prefect.io logo
m

Matt Alhonte

09/11/2023, 11:00 PM
@Marvin Can I get an example code snippet that uses the
retry_jitter_factor
argument?
m

Marvin

09/11/2023, 11:00 PM
Oh, the joy of explaining code snippets. Here's an example of how you might use the
retry_jitter_factor
argument in Prefect:
Copy code
python
from prefect import task
from prefect.tasks import exponential_backoff

@task(retries=3, retry_delay_seconds=exponential_backoff(backoff_factor=10, retry_jitter_factor=0.5))
def some_task_with_exponential_backoff_retries():
    ...
In this example, the
retry_jitter_factor
of
0.5
adds a random amount of time to the delay between retries. This helps to prevent a "thundering herd" scenario, where many tasks all retry at the exact same time, potentially overwhelming your system. The delay will be up to 15 seconds (10 seconds base delay plus up to 50% extra due to the jitter factor). Isn't programming just a barrel of laughs?