RETRY | R Documentation |
Safely retry a request until it succeeds, as defined by the terminate_on
parameter, which by default means a response for which http_error()
is FALSE
. Will also retry on error conditions raised by the underlying curl code,
but if the last retry still raises one, RETRY
will raise it again with
stop()
.
It is designed to be kind to the server: after each failure
randomly waits up to twice as long. (Technically it uses exponential
backoff with jitter, using the approach outlined in
https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/.)
If the server returns status code 429 and specifies a retry-after
value, that
value will be used instead, unless it's smaller than pause_min
.
RETRY(
verb,
url = NULL,
config = list(),
...,
body = NULL,
encode = c("multipart", "form", "json", "raw"),
times = 3,
pause_base = 1,
pause_cap = 60,
pause_min = 1,
handle = NULL,
quiet = FALSE,
terminate_on = NULL,
terminate_on_success = TRUE
)
verb |
Name of verb to use. |
url |
the url of the page to retrieve |
config |
Additional configuration settings such as http
authentication ( |
... |
Further named parameters, such as |
body |
One of the following:
|
encode |
If the body is a named list, how should it be encoded? Can be one of form (application/x-www-form-urlencoded), multipart, (multipart/form-data), or json (application/json). For "multipart", list elements can be strings or objects created by
|
times |
Maximum number of requests to attempt. |
pause_base, pause_cap |
This method uses exponential back-off with full
jitter - this means that each request will randomly wait between
|
pause_min |
Minimum time to wait in the backoff; generally only necessary if you need pauses less than one second (which may not be kind to the server, use with caution!). |
handle |
The handle to use with this request. If not
supplied, will be retrieved and reused from the |
quiet |
If |
terminate_on |
Optional vector of numeric HTTP status codes that if found
on the response will terminate the retry process. If |
terminate_on_success |
If |
The last response. Note that if the request doesn't succeed after
times
times this will be a failed request, i.e. you still need
to use stop_for_status()
.
## Not run:
# Succeeds straight away
RETRY("GET", "http://httpbin.org/status/200")
# Never succeeds
RETRY("GET", "http://httpbin.org/status/500")
# Invalid hostname generates curl error condition and is retried but eventually
# raises an error condition.
RETRY("GET", "http://invalidhostname/")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.