Skip to content

Commit d622810

Browse files
committed
Sheets quotas have changed a bit
Relates to r-lib#248, weakly
1 parent cf5ff4d commit d622810

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

R/request_retry.R

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#' convention, is usually written in terms of powers of 2:
2626
#'
2727
#' ```
28-
#' b , 2b, 4b, 8b, ...
28+
#' b, 2b, 4b, 8b, ...
2929
#' = b * 2^0, b * 2^1, b * 2^2, b * 2^3, ...
3030
#' ```
3131
#'
@@ -64,13 +64,14 @@
6464
#' can alternatively provide a datetime after which to retry, but we have no
6565
#' first-hand experience with this variant for a Google API.)
6666
#' * Sheets API quota exhaustion: In the course of googlesheets4 development,
67-
#' we've grown very familiar with the `429 RESOURCE_EXHAUSTED` error. The
68-
#' Sheets API v4 has "a limit of 500 requests per 100 seconds per project and
69-
#' 100 requests per 100 seconds per user. Limits for reads and writes are
70-
#' tracked separately." In our experience, the "100 (read or write) requests
71-
#' per 100 seconds per user" limit is the one you hit most often. If we detect
72-
#' this specific failure, the first wait time is a bit more than 100 seconds,
73-
#' then we revert to exponential backoff.
67+
#' we've grown very familiar with the `429 RESOURCE_EXHAUSTED` error. As of
68+
#' 2023-04-15, the Sheets API v4 has a limit of 300 requests per minute per
69+
#' project and 60 requests per minute per user per project. Limits for reads
70+
#' and writes are tracked separately. In our experience, the "60 (read or
71+
#' write) requests per minute per user" limit is the one you hit most often.
72+
#' If we detect this specific failure, the first wait time is a bit more than
73+
#' one minute, then we revert to exponential backoff.
74+
#'
7475
#'
7576
#' @param ... Passed along to [request_make()].
7677
#' @param max_tries_total Maximum number of tries.
@@ -155,8 +156,8 @@ backoff <- function(tries_made,
155156
}
156157

157158
if (sheets_per_user_quota_exhaustion(resp) && tries_made == 1) {
158-
wait_time <- 100 + stats::runif(1)
159-
wait_rationale <- "fixed 100 second wait for per user quota exhaustion"
159+
wait_time <- 60 + stats::runif(1)
160+
wait_rationale <- "fixed 60 second wait for per user quota exhaustion"
160161
}
161162

162163
retry_after <- retry_after_header(resp)
@@ -203,7 +204,7 @@ sheets_per_user_quota_exhaustion <- function(resp) {
203204
msg <- gargle_error_message(resp)
204205
# the structure of this error and the wording of this message have changed
205206
# over time
206-
any(grepl("per user per 100 seconds", msg)) ||
207+
any(grepl("per user per 60 seconds", msg)) ||
207208
any(grepl("per minute per user", msg))
208209
}
209210

man/request_retry.Rd

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/fixtures/sheets-spreadsheets-get-quota-exceeded-readgroup_429.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ f <- function(ssid = deaths_id, i = 0) {
77
"sheets.spreadsheets.get",
88
params = list(spreadsheetId = ssid, fields = "spreadsheetId")
99
)
10-
raw_resp <- googlesheets4::request_make(req)
10+
raw_resp <- gargle::request_make(req)
1111
code <- httr::status_code(raw_resp)
1212
cat(i, "code:", code, "\n")
1313
if (code >= 200 && code < 300) {
Binary file not shown.

0 commit comments

Comments
 (0)