zulip / python-zulip-api

Python library for the Zulip API.
https://zulip.com/api/
Apache License 2.0
350 stars 352 forks source link

zulip.Client.call_endpoint: Add retry_on_rate_limit_error. #705

Open ro-i opened 3 years ago

ro-i commented 3 years ago

Hi :)

I'd like to suggest a new option for the call_endpoint method of zulip.Client. It's something I added to my bot. @timabbott suggested to also consider this for the API, see https://chat.zulip.org/#narrow/stream/378-api-design/topic/Rate.20limits/near/1217048 for the discussion.

Short description of the patch: If the call_endpoint method is called with the retry_on_rate_limit_error parameter set to true, wait and retry automatically on rate limit errors.

ro-i commented 3 years ago

@timabbott Thanks for the feedback! :+1: I updated the code (the layout of the if-statement with the closing bracket on its own line has been done by ./tools/lint btw. ;) ). And you would also think that retry-after has always been a float, not a string? I'm not sure how that has been handled by older Zulip versions. And I'm not sure what happened to the capitalized Retry-After I found here...