Skip to content

Commit

Permalink
add tidyhydat_perform
Browse files Browse the repository at this point in the history
  • Loading branch information
boshek committed Jan 4, 2024
1 parent ea40b4d commit 9082377
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 3 additions & 4 deletions R/download.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ download_hydat <- function(dl_hydat_here = NULL, ask = TRUE) {
req <- httr2::request(url)
req <- httr2::req_method(req, "HEAD")
req <- tidyhydat_agent(req)
req <- req_perform(req)
req <- tidyhydat_perform(req)
httr2::resp_check_status(req)

size <- round(as.numeric(
Expand All @@ -83,7 +83,6 @@ download_hydat <- function(dl_hydat_here = NULL, ask = TRUE) {
if (!dl_overwrite) {
info("HYDAT is updated on a quarterly basis, check again soon for an updated version.")
}
browser()
if (new_hydat != existing_hydat & ask) { # New DB available or no local DB at all
msg <- paste0(
"This version of HYDAT is ", size, "MB in size and will take some time to download.
Expand Down Expand Up @@ -114,7 +113,7 @@ download_hydat <- function(dl_hydat_here = NULL, ask = TRUE) {
## Download the zip file
hydb_req <- httr2::request(url)
hydb_req <- tidyhydat_agent(hydb_req)
resp <- req_perform(hydb_req, tmp)
resp <- tidyhydat_perform(hydb_req, path = tmp)
httr2::resp_check_status(resp)

## Extract the file to a temporary dir
Expand Down Expand Up @@ -157,7 +156,7 @@ hy_remote <- function() {
network_check(hy_base_url())

req <- httr2::request(hy_base_url())
req <- httr2::req_perform(req)
req <- tidyhydat_perform(req)
resp <- httr2::resp_check_status(req)


Expand Down
6 changes: 6 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,10 @@ hy_expected_tbls <- function() {
is_mac <- function() {
system_info <- Sys.info()
grepl("darwin", tolower(system_info["sysname"]))
}

tidyhydat_perform <- function(req, ...) {
req <- httr2::req_retry(req, max_tries = 5)
req <- httr2::req_progress(req)
httr2::req_perform(req, ...)
}

0 comments on commit 9082377

Please sign in to comment.