Skip to content

Commit 78e97ed

Browse files
committed
refactor+doc: update default timeout_seconds to 15 minutes.
Also remove some timeout_seconds-related defaults from a few internal request functions, since they almost always receive a default value from upstream, to reduce the number of places the default value is hardcoded. Fix all calls to those functions to include arguments.
1 parent 75a6ec8 commit 78e97ed

File tree

11 files changed

+33
-21
lines changed

11 files changed

+33
-21
lines changed

.github/pull_request_template.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
Please:
44

5-
- [ ] Make sure this PR is against "dev", not "main".
5+
- [ ] Make sure this PR is against "dev", not "main" (unless this is a release
6+
PR).
67
- [ ] Request a review from one of the current epiprocess main reviewers:
78
brookslogan, nmdefries.
8-
- [ ] Makes sure to bump the version number in `DESCRIPTION` and `NEWS.md`.
9-
Always increment the patch version number (the third number), unless you are
10-
making a release PR from dev to main, in which case increment the minor
11-
version number (the second number).
9+
- [ ] Makes sure to bump the version number in `DESCRIPTION`. Always increment
10+
the patch version number (the third number), unless you are making a
11+
release PR from dev to main, in which case increment the minor version
12+
number (the second number).
1213
- [ ] Describe changes made in NEWS.md, making sure breaking changes
1314
(backwards-incompatible changes to the documented interface) are noted.
1415
Collect the changes under the next release number (e.g. if you are on

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: epidatr
22
Type: Package
33
Title: Client for Delphi's 'Epidata' API
4-
Version: 1.0.1
4+
Version: 1.0.2
55
Date: 2023-12-07
66
Authors@R:
77
c(

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- `pvt_twitter` and `pub_wiki` now use `time_type` and `time_values` args instead of mutually exclusive `dates` and `epiweeks` (#236). This matches the interface of the `pub_covidcast` endpoint.
2424
- All endpoints now support the use of "\*" as a wildcard to fetch all dates or epiweeks (#234).
2525
- Fixed bug with NAs when parsing ints (#243).
26+
- Updated the default `timeout_seconds` to 15 minutes to allow large queries by default.
2627

2728
# epidatr 1.0.0
2829

R/epidatacall.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ create_epidata_call <- function(endpoint, params, meta = NULL,
8989
}
9090

9191
#' @importFrom checkmate test_class test_list
92-
request_arguments <- function(epidata_call, format_type, fields = NULL) {
92+
request_arguments <- function(epidata_call, format_type, fields) {
9393
stopifnot(inherits(epidata_call, "epidata_call"))
9494
stopifnot(format_type %in% c("json", "csv", "classic"))
9595
stopifnot(is.null(fields) || is.character(fields))
@@ -164,7 +164,7 @@ fetch_args_list <- function(
164164
disable_date_parsing = FALSE,
165165
disable_data_frame_parsing = FALSE,
166166
return_empty = FALSE,
167-
timeout_seconds = 30,
167+
timeout_seconds = 15 * 60,
168168
base_url = NULL,
169169
dry_run = FALSE,
170170
debug = FALSE,
@@ -288,7 +288,7 @@ fetch_classic <- function(epidata_call, fetch_args = fetch_args_list()) {
288288
stopifnot(inherits(epidata_call, "epidata_call"))
289289
stopifnot(inherits(fetch_args, "fetch_args"))
290290

291-
response_content <- request_impl(epidata_call, "classic", fetch_args$fields, fetch_args$timeout_seconds) %>%
291+
response_content <- request_impl(epidata_call, "classic", fetch_args$timeout_seconds, fetch_args$fields) %>%
292292
httr::content(as = "text", encoding = "UTF-8") %>%
293293
jsonlite::fromJSON(simplifyDataFrame = !fetch_args$disable_data_frame_parsing)
294294

@@ -318,7 +318,7 @@ fetch_debug <- function(epidata_call, fetch_args = fetch_args_list()) {
318318
stopifnot(inherits(epidata_call, "epidata_call"))
319319
stopifnot(inherits(fetch_args, "fetch_args"))
320320

321-
response <- request_impl(epidata_call, fetch_args$format_type, fetch_args$fields, fetch_args$timeout_seconds)
321+
response <- request_impl(epidata_call, fetch_args$format_type, fetch_args$timeout_seconds, fetch_args$fields)
322322
content <- httr::content(response, "text", encoding = "UTF-8")
323323
content
324324
}
@@ -366,7 +366,7 @@ with_base_url <- function(epidata_call, base_url) {
366366
#' @importFrom httr stop_for_status content http_type
367367
#' @importFrom xml2 read_html xml_find_all xml_text
368368
#' @keywords internal
369-
request_impl <- function(epidata_call, format_type, fields = NULL, timeout_seconds = 30) {
369+
request_impl <- function(epidata_call, format_type, timeout_seconds, fields) {
370370
stopifnot(inherits(epidata_call, "epidata_call"))
371371
stopifnot(format_type %in% c("json", "csv", "classic"))
372372

R/request.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ join_url <- function(url, endpoint) {
2222
#'
2323
#' @importFrom httr RETRY
2424
#' @keywords internal
25-
do_request <- function(url, params, timeout_seconds = 30) {
25+
do_request <- function(url, params, timeout_seconds) {
2626
# don't retry in case of certain status codes
2727
key <- get_api_key()
2828
if (key != "") {

man/do_request.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fetch_args_list.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/request_impl.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/generate_test_data.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ epidata_call %>%
44

55
url <- full_url(epidata_call)
66
params <- request_arguments(epidata_call, "csv", NULL)
7-
result <- do_request(url, params) %>% readr::write_rds(testthat::test_path("data/test-http401.rds"))
7+
result <- do_request(url, params, timeout_seconds = 10 * 60) %>%
8+
readr::write_rds(testthat::test_path("data/test-http401.rds"))
89

910
epidata_call <- pvt_afhsb(
1011
auth = Sys.getenv("SECRET_API_AUTH_AFHSB"),
@@ -14,7 +15,8 @@ epidata_call <- pvt_afhsb(
1415
)
1516
url <- full_url(epidata_call)
1617
params <- request_arguments(epidata_call, "csv", NULL)
17-
response <- do_request(url, params) %>% readr::write_rds(testthat::test_path("data/test-http500.rds"))
18+
response <- do_request(url, params, timeout_seconds = 10 * 60) %>%
19+
readr::write_rds(testthat::test_path("data/test-http500.rds"))
1820

1921
epidata_call %>%
2022
fetch_debug(format_type = "classic") %>%

tests/testthat/test-epidatacall.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@ test_that("request_impl http errors", {
1010
# see generate_test_data.R
1111
do_request = function(...) readRDS(testthat::test_path("data/test-http401.rds")),
1212
)
13-
expect_error(response <- epidata_call %>% request_impl("csv"), class = "http_401")
13+
expect_error(
14+
response <- epidata_call %>%
15+
request_impl("csv", timeout_seconds = 30, fields = NULL),
16+
class = "http_401"
17+
)
1418

1519
# should give a 500 error (the afhsb endpoint is removed)
1620

1721
# see generate_test_data.R
1822
local_mocked_bindings(
1923
do_request = function(...) readRDS(testthat::test_path("data/test-http500.rds"))
2024
)
21-
expect_error(response <- epidata_call %>% request_impl("csv"), class = "http_500")
25+
expect_error(
26+
response <- epidata_call %>%
27+
request_impl("csv", timeout_seconds = 30, fields = NULL),
28+
class = "http_500"
29+
)
2230
})
2331

2432
test_that("fetch_args", {
@@ -30,7 +38,7 @@ test_that("fetch_args", {
3038
disable_date_parsing = FALSE,
3139
disable_data_frame_parsing = FALSE,
3240
return_empty = FALSE,
33-
timeout_seconds = 30,
41+
timeout_seconds = 15 * 60,
3442
base_url = NULL,
3543
dry_run = FALSE,
3644
debug = FALSE,

0 commit comments

Comments
 (0)