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

Feature request: add max_tries to insistently() #1049

Open
mmuurr opened this issue Jan 24, 2023 · 2 comments
Open

Feature request: add max_tries to insistently() #1049

mmuurr opened this issue Jan 24, 2023 · 2 comments
Labels
adverb 📚 feature a feature request or enhancement

Comments

@mmuurr
Copy link

mmuurr commented Jan 24, 2023

Would be useful to have a {purrr} adverb that is similar to {httr2}'s req_retry().

I think(?) adding a max_tries = Inf (or NULL default) param to insistently() wouldn't scope-creep too much, and let insistently() signal the (final) error once the retry count is exhausted.

An motivating use case is wrapping a function that delegates to some system call (e.g. via {processx}) that itself might be making network calls with some potential failure rate. (My particular instance of this is with wrapping some AWS CLI calls, which can fail due to intermitent network issues.)

@hadley
Copy link
Member

hadley commented Feb 5, 2023

Should probably mimic https://httr2.r-lib.org/reference/req_retry.html and provide both max_tries and max_seconds.

Would be useful to have this also as something you can use on a block of code, not just a function.

@hadley
Copy link
Member

hadley commented Feb 7, 2023

There is already a max_tries argument, but it's hard to see because it's an argument to rate_backoff():

library(purrr)

f <- local({
  i <- 0
  f <- function() {
    i <- i + 1
    if (i < 5) stop("Error")
    i * 10
  }
}) 
insistently(f)(1)
#> Error in `rate_sleep()`:
#> ! Request failed after 3 attempts.

#> Backtrace:
#>     ▆
#>  1. └─insistently(f)(1)
#>  2.   └─purrr::rate_sleep(rate, quiet = quiet)
#>  3.     └─purrr:::stop_rate_excess(rate)
#>  4.       └─cli::cli_abort(...)
#>  5.         └─rlang::abort(...)

Created on 2023-02-07 with reprex v2.0.2

I think we're now somewhat moving away from these adverbs (in hindsight their names seem too clever), but I'll probably implement with_retries() shortly.

@hadley hadley added feature a feature request or enhancement adverb 📚 labels Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adverb 📚 feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants