r-lib / gargle

Infrastructure for calling Google APIs from R, including auth
https://gargle.r-lib.org/
Other
113 stars 33 forks source link

Give the developer a small window of opportunity to know about retries #248

Open gadenbuie opened 1 year ago

gadenbuie commented 1 year ago

When working with gargle via a package like googlesheets, failed requests are automatically retried. This is excellent and it means requests almost always make it through.

The downside is that the retries understandably backoff rather aggressively, so the wait time can be quite long, up to 100 seconds by default. In a Shiny app, this can be an eternity of waiting for the end user, and it'd be helpful for the app author to be able to give some feedback on the progress of the request.

The feature request is for gargle to offer some window of opportunity to know that a retry has happened and to run code before the next retry occurs.

Just brainstorming, two potential ways to do this could be:

  1. gargle::request_retry() could execute a callback function, found via an R option, before calling Sys.sleep().
  2. gargle::request_retry() could take inspiration from rlang::check_installed() and signal a known condition with restarts. This would give (admittedly expert) users a chance to run code before returning control to request_retry().
jennybc commented 1 year ago

the wait time can be quite long, up to 100 seconds by default

just to clarify this one point, that is specific to the Sheets API, which has very specific per user quotas

It looks like those have changed since I last set up the special case for Sheets retries, so maybe I don't need the 100 seconds thing any more:

https://developers.google.com/sheets/api/limits