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

Check API status / Automated retry logic #418

Open
Romans96 opened this issue Dec 10, 2020 · 5 comments · May be fixed by #525 or #707
Open

Check API status / Automated retry logic #418

Romans96 opened this issue Dec 10, 2020 · 5 comments · May be fixed by #525 or #707

Comments

@Romans96
Copy link

Hello! Is it possible to check the API status? How?

For example how many request are made, if i have other available requests, the rate limit per hour, etc?

Thank you!

@Romans96
Copy link
Author

SO nobody knows? When it ends the usage limit it stops and the app crashes without no errors no returns and i cannot find any way to handle the "Usgae limit reach"

@theoephraim
Copy link
Owner

It should be throwing an error of some kind - so either you need to wrap your calls in try catches, or have a global uncaught error handler registered.

I am not aware of any way to check it programatically, but we could potentially build in handling that would retry the request after some delay.

@darraghmckay darraghmckay linked a pull request Dec 3, 2021 that will close this issue
@theoephraim
Copy link
Owner

I'll take a look at getting something like this merged in soon.

@theoephraim theoephraim changed the title Check API status Check API status / Automated retry logic Jun 27, 2023
@agladysh
Copy link

It would be very nice to have the retry logic. I have a large spreadsheet with many worksheets, and cannot read it without hitting a rate limit.

Here is my workaround, in case it helps someone while there is no native support for rate limits in the module:

      //  Very rough ad-hoc implementation of https://developers.google.com/sheets/api/limits
      const maxBackoff = 32000;
      const maxRetries = 16;
      let retryNumber = 0;

      async function tryDownloadAsCSV(): Promise<ArrayBuffer> {
        return await sheet.downloadAsCSV().catch(async (e: AxiosError) => {
          if (e.response?.status !== 429) {
            throw e;
          }

          if (++retryNumber > maxRetries) {
            throw e;
          }

          const delay = Math.ceil(Math.min(maxBackoff, 100 + Math.pow(2, retryNumber) * 100) + Math.random() * 100);

          console.log(`[${retryNumber} / ${maxRetries}] got 429 from Google Sheets, waiting for ${delay} ms`);

          return new Promise(resolve => setTimeout(() => {
            resolve(tryDownloadAsCSV());
          }, delay));
        });
      }

      const buffer = await tryDownloadAsCSV();

See also: #326 #525

@charlesgardyn
Copy link

charlesgardyn commented Dec 18, 2023

I'm using this #525 (comment) as a workaround while the PR is not merged

@Niallfitzy1 Niallfitzy1 linked a pull request Oct 16, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants