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

replaced single-shot HTTP requests with RETRY logic #235

Merged
merged 2 commits into from
Apr 27, 2020
Merged

replaced single-shot HTTP requests with RETRY logic #235

merged 2 commits into from
Apr 27, 2020

Conversation

jameslamb
Copy link
Contributor

In this PR, I'd like to propose swapping out calls to httr::POST() etc. with httr::RETRY(). It looks like you're already using RETRY() in a lot of places, which is awesome! This PR just changes the few remaining places where you weren't.

This will make the package more resilient to transient problems like brief network outages or periods where the service(s) it hits are overwhelmed. In my experience, using retry logic almost always improves the user experience with HTTP clients.

I also noticed that you are mocking httr::VERB() but that it's never called in the code, so I removed those mocks.

I'm working on chircollab/chircollab20#1 as part of Chicago R Collab, an R 'unconference' in Chicago.

Thanks for your time and consideration!

Copy link
Contributor

@mheilman mheilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I had a minor suggestion.

Also, could you please add a line to the unreleased section in CHANGELOG.md?

R/io.R Outdated
@@ -258,7 +258,7 @@ write_civis.character <- function(x, tablename, database = NULL, if_exists = "fa
credential_id = credential_id),
import_args)
job_r <- do.call(start_import_job, args)
put_r <- httr::PUT(job_r[["uploadUri"]], body = httr::upload_file(x))
put_r <- httr::RETRY("PUT", job_r[["uploadUri"]], body = httr::upload_file(x), terminate_on = c(403, 404))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be better to terminate on any 4xx error other 429 here (e.g., terminate_on = setdiff(400:499, 429)). That's what AWS recommends here, and this URI and the one for write_disk below will be S3 URLs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure I can do that! setdiff() is a super clean way to express it, I like it 😀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed the comments in 7cdb800

R/io.R Outdated
list(httr::write_disk(file, overwrite = overwrite)))
list(httr::write_disk(file, overwrite = overwrite)),
verb = "GET",
terminate_on = c(403, 404))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also please make this terminate_on = setdiff(400:499, 429)? Sorry, I should have commented about each case rather than just the first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sure, no problem!

R/io.R Outdated
@@ -902,14 +904,14 @@ download_script_results <- function(script_id, run_id,
stop_if_no_output(script_results)

url <- script_results[["output"]][[1]][["path"]]
args <- list(url)
args <- list(url, verb = "GET", terminate_on = c(403, 404))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also please make this terminate_on = setdiff(400:499, 429)?

@jameslamb
Copy link
Contributor Author

I pushed #235 to address the most recent review comments

Copy link
Contributor

@mheilman mheilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@mheilman
Copy link
Contributor

@jameslamb, would you care to merge this? (no rush, I just noticed this was still open)

@jameslamb
Copy link
Contributor Author

@jameslamb, would you care to merge this? (no rush, I just noticed this was still open)

@mheilman I don't have permission to merge pull requests in this repository. That has to be done by a maintainer.

image

@mheilman
Copy link
Contributor

Oh, my bad, sorry. I forgot about that! I thought you could merge if it was approved by a maintainer or something.

@mheilman mheilman merged commit 0e30227 into civisanalytics:master Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants