Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle 429 responses from Chat API #41

Merged
merged 2 commits into from
Nov 5, 2024
Merged

Conversation

akash1810
Copy link
Member

@akash1810 akash1810 commented Nov 5, 2024

What does this change?

Retry a Google Chat API request 1.5 seconds after receipt of a 429 response. This should help avoid the rate limit of this API (60 requests per minute).

Example output w/unhandled 429 responses

image

How to test

Following the README instructions:

  • Run main, observe a 429 response and program exit
  • Run this branch and observe a retry on a 429 response

Alternatively, see guardian/prnouncer-config#71 and it's execution.


Fixes #40.

akash1810 added a commit to guardian/prnouncer-config that referenced this pull request Nov 5, 2024
The Google Chat API has a rate limit of 60 requests per minute.
Sleep for 1.5 seconds after a 429 response.

See https://developers.google.com/workspace/chat/limits.
@akash1810 akash1810 marked this pull request as ready for review November 5, 2024 07:11
src/google.rs Outdated
response.status()
);
tokio::time::sleep(time::Duration::from_millis(1500)).await;
Box::pin(self.send(webhook_url, thread_key)).await
Copy link
Member Author

@akash1810 akash1810 Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A terminating ; doesn't compile. I don't know Rust well enough to comment why - any help welcomed!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expressions without a semicolon return a value to the containing function or block. Expressions with a semicolon become statements and do not return a value.

@akash1810 akash1810 merged commit d89cecf into main Nov 5, 2024
8 checks passed
@akash1810 akash1810 deleted the aa/chat-rate-limit branch November 5, 2024 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle 429 responses from Google Chat API
2 participants