Skip to content

Commit

Permalink
Merge branch 'master' into 89-parameter-emailoncompletion-should-not-…
Browse files Browse the repository at this point in the history
…e-mail-a-junk-address-by-default
  • Loading branch information
Robinlovelace committed Dec 4, 2024
2 parents 88c94cc + aeaac30 commit 81904d4
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*.Rds
*.csv
*.gz
.devcontainer/
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: cyclestreets
Title: Cycle Routing and Data for Cycling Advocacy
Version: 1.0.1
Version: 1.0.3
Authors@R: c(
person("Robin", "Lovelace", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5679-6536")),
Expand All @@ -10,7 +10,9 @@ Authors@R: c(
person("Joey", "Talbot", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-6520-4560")),
person("Malcolm", "Morgan", role = "ctb",
comment = c(ORCID = "0000-0002-9488-9183"))
comment = c(ORCID = "0000-0002-9488-9183")),
person("Zhao", "Wang", role = "ctb",
comment = c(ORCID = "0000-0002-4054-0533"))
)
Description: An interface to the cycle routing/data services provided by
'CycleStreets', a not-for-profit social enterprise and advocacy
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# cyclestreets 1.0.3 (2024-12)

* Increased timeout time (#91)
* Use retry
* Added Wang Zhao to DESCRIPTION file

# cyclestreets 1.0.2 (2024-09)

* Minor update to fix an issue with the `batch()` function (#91)

# cyclestreets 1.0.1

* Bug fix: issue with batch identified and fix (#80) thanks to @mem48
Expand Down
56 changes: 49 additions & 7 deletions R/batch.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@
#' if(FALSE) {
#' library(sf)
#' desire_lines = od::od_to_sf(od::od_data_df, od::od_data_zones)[4:5, 1:3]
#' u = paste0("https://github.com/cyclestreets/cyclestreets-r/",
#' "releases/download/v0.5.3/od-longford-10-test.Rds")
#' u1 = "https://github.com/cyclestreets/cyclestreets-r/"
#' u2 = "releases/download/v0.5.3/od-longford-10-test.Rds"
#' u = paste0(u1, u2)
#' desire_lines = readRDS(url(u))
#' routes_id = batch(desire_lines, username = "robinlovelace", wait = FALSE)
#' # Wait for some time, around a minute or 2
Expand Down Expand Up @@ -208,7 +209,21 @@ get_routes = function(url, desire_lines = NULL, filename, directory,
if(file.exists(filename_local)) {
message(filename, " already exists, overwriting it")
}
httr::GET(url, httr::write_disk(filename_local, overwrite = TRUE))
httr::RETRY(
"GET",
url,
httr::write_disk(filename_local, overwrite = TRUE),
httr::timeout(60 * 60 * 10),
httr::config(connecttimeout = 60 * 60 * 10),
times = 5,
pause_base = 2,
pause_cap = 600, # Increased maximum pause cap
pause_min = 30,
terminate_on = NULL,
retry_on = NULL
# httr::verbose()
)

# R.utils::gzip(filename_local)
# routes = batch_read(gsub(pattern = ".gz", replacement = "", filename_local))
# list.files(tempdir())
Expand Down Expand Up @@ -307,7 +322,21 @@ batch_routes = function(
}

# # With httr:
res = httr::POST(url = batch_url, body = body, httr::timeout(600))
res = httr::RETRY(
"POST",
url = batch_url,
body = body,
httr::timeout(60 * 60 * 10),
httr::config(connecttimeout = 60 * 60 * 10),
times = 5, # Number of retries
pause_base = 2, # Base delay between retries
pause_cap = 600, # Max delay between retries
pause_min = 30, # Min delay between retries
terminate_on = NULL, # Don't terminate on specific status codes
retry_on = NULL # Retry on all errors (since connection refused isn't an HTTP status code)
# httr::verbose() # Optional: outputs detailed request info
)

res_json = httr::content(res, "parsed")

# # # With httr2:
Expand Down Expand Up @@ -339,7 +368,7 @@ batch_control = function(base_url = "https://api.cyclestreets.net/v2/batchroutes
username = username,
password = Sys.getenv("CYCLESTREETS_PW")
)
httr::POST(url = batch_url, body = body)
httr::POST(url = batch_url, body = body, httr::timeout(60*60*5))
}

batch_jobdata = function(
Expand All @@ -359,7 +388,20 @@ batch_jobdata = function(
)
# TODO add polling
if(!silent) message("Sending data, wait...")
res = httr::POST(url = batch_url, body = body)
res = httr::RETRY(
"POST",
url = batch_url,
body = body,
httr::timeout(60 * 60 * 10),
httr::config(connecttimeout = 60 * 60 * 10),
times = 5,
pause_base = 2,
pause_cap = 600,
pause_min = 30,
terminate_on = NULL,
retry_on = NULL
# httr::verbose()
)
res_json = httr::content(res, "parsed")
error_message = paste0(" ", as.character(res_json$error))
# Print message if silent = FALSE
Expand Down Expand Up @@ -411,7 +453,7 @@ batch_deletejob = function(
)
# TODO add polling
if(!silent) message("Deleting the data")
res = httr::POST(url = batch_url, body = body)
res = httr::POST(url = batch_url, body = body, httr::timeout(60*60*5), httr::config(connecttimeout = 60 * 60 * 10))
res_json = httr::content(res, "parsed")
message("Job ",paste0(res_json, collapse = ": "))
}
Expand Down
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
We found a bug in the previous release, apologies for the submission of 2 versions in quick succession
Minor patches.

## R CMD check results

Expand Down

0 comments on commit 81904d4

Please sign in to comment.