I have a large number of flows calling an API and ...
# ask-community
d
I have a large number of flows calling an API and I keep getting 429'd. Is there a built in mechanism to set task retry delay to the duration specified in the Retry-After response header from the external API? Or is it possible to base the retry logic on the task result?
n
hey @Daniel Lomartra - to be clear, you're hitting some other API for your flow, and you're getting 429s from us? or from that other api
d
The other API
c
@Daniel Lomartra Why don't you just set a timeout within the task and retry afterwards? Something like this:
@task
def my_api_calling_task():
while True:
res = requests.get('<http://my-api.com/api>')
if res.status_code = 429:
time.sleep(res.headers['Retry-After'])
else:
return res.json()
d
Thank you. Yeah I could. The times are pretty consistent so I ended up just setting static retries with some jitter. Thought it would be cleaner to use prefects built-in retries though and seems like it would be a supported use case given how common it is to recieve 429.