Skip to content

Commit

Permalink
move GET_retry method from ghcnd.R file to zzz.R
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jun 8, 2020
1 parent b2f85d6 commit a2c840d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
17 changes: 0 additions & 17 deletions R/ghcnd.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,6 @@ strex <- function(x) str_extract_(x, "[0-9]+")
as_tc <- function(x) textConnection(enc2utf8(rawToChar(x)))
as_tc_p <- function(x) textConnection(x$parse("latin1"))

GET_retry <- function(url, ..., times = 3) {
cliret <- crul::HttpClient$new(url)
res <- suppressWarnings(cliret$get(...))
if (res$status_code > 226) {
message("Request failed - Retrying")
stat <- 500
i <- 0
while (stat > 226 && i <= times) {
i <- i + 1
res <- suppressWarnings(cliret$get(...))
stat <- res$status_code
}
if (res$status_code > 226) stop("Request failed, try again", call. = FALSE)
}
return(res)
}

ghcnd_GET <- function(stationid, ...){
ghcnd_cache$mkdir()
fp <- ghcnd_local(stationid)
Expand Down
17 changes: 17 additions & 0 deletions R/zzz.r
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,20 @@ assert <- function(x, y) {
}
}
}

GET_retry <- function(url, ..., times = 3) {
cliret <- crul::HttpClient$new(url)
res <- suppressWarnings(cliret$get(...))
if (res$status_code > 226) {
message("Request failed - Retrying")
stat <- 500
i <- 0
while (stat > 226 && i <= times) {
i <- i + 1
res <- suppressWarnings(cliret$get(...))
stat <- res$status_code
}
if (res$status_code > 226) stop("Request failed, try again", call. = FALSE)
}
return(res)
}

0 comments on commit a2c840d

Please sign in to comment.