diff --git a/R/schematic_rest_api.R b/R/schematic_rest_api.R index d4025ffd..570af6e8 100644 --- a/R/schematic_rest_api.R +++ b/R/schematic_rest_api.R @@ -112,7 +112,8 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate", schema_url="https://raw.githubusercontent.com/ncihtan/data-models/main/HTAN.model.jsonld", #nolint data_type, file_name = NULL, restrict_rules=FALSE, project_scope = NULL, access_token, asset_view = NULL, json_str = NULL) { - + a <- paste0(sample(1000, 1), "-") + cat(paste0(a, "-validate func ", data_type, " ", file_name, "\n")) flattenbody <- function(x) { # A form/query can only have one value per name, so take # any values that contain vectors length >1 and @@ -137,8 +138,15 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate", } if (is.null(json_str)) { - req <- httr2::request(url) - resp <- req %>% + reqs <- httr2::request(url) |> + httr2::req_retry( + max_tries = 3, + is_transient = \(reqs) httr2::resp_status(reqs) %in% c(429, 500, 503, 504) + ) |> + httr2::req_error(is_error = \(reqs) FALSE) |> + httr2::req_throttle(1) + cat(paste0(a, "-validate func requesting", unlist(reqs), "\n")) + resp <- reqs %>% httr2::req_headers(Authorization = sprintf("Bearer %s", access_token)) |> httr2::req_url_query( schema_url=schema_url, @@ -148,14 +156,11 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate", asset_view = asset_view ) |> httr2::req_body_multipart(file_name=curl::form_file(file_name)) |> - httr2::req_retry( - max_tries = 3, - is_transient = \(resp) httr2::resp_status(resp) %in% c(429, 500, 503, 504) - ) |> - httr2::req_error(is_error = \(resp) FALSE) |> httr2::req_perform() + cat(paste0(a, "-validate func response", unlist(resp), "\n")) } else { - req <- httr2::request(url) + req <- httr2::request(url) |> + httr2::req_throttle(1) resp <- req %>% httr2::req_headers(Authorization = sprintf("Bearer %s", access_token)) |> httr2::req_url_query( @@ -166,15 +171,16 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate", asset_view = asset_view, json_str = json_str ) |> - httr2::req_retry( - max_tries = 3, - is_transient = \(resp) httr2::resp_status(resp) %in% c(429, 500, 503, 504) - ) |> - httr2::req_error(is_error = \(resp) FALSE) |> + #httr2::req_retry( + # max_tries = 3, + # is_transient = \(resp) httr2::resp_status(resp) %in% c(429, 500, 503, 504) + #) |> + #httr2::req_error(is_error = \(resp) FALSE) |> httr2::req_perform() } # Format server error in a way validationResult can handle + cat(a, "-validate func response", "\n") if (httr2::resp_is_error(resp)) { return( list( @@ -243,14 +249,15 @@ model_component_requirements <- function(url="http://localhost:3001/v1/model/com schema_url, source_component, as_graph = FALSE) { - req <- httr2::request(url) - resp <- req |> + reqs <- httr2::request(url) |> + httr2::req_throttle(1) + resp <- reqs |> httr2::req_url_query( schema_url = schema_url, source_component = source_component, as_graph = as_graph ) |> - httr2::req_retry(max_tries = 3) |> + #httr2::req_retry(max_tries = 3) |> httr2::req_perform() resp |> httr2::resp_body_json() diff --git a/functions/schematic_rest_api.R b/functions/schematic_rest_api.R index d4025ffd..570af6e8 100644 --- a/functions/schematic_rest_api.R +++ b/functions/schematic_rest_api.R @@ -112,7 +112,8 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate", schema_url="https://raw.githubusercontent.com/ncihtan/data-models/main/HTAN.model.jsonld", #nolint data_type, file_name = NULL, restrict_rules=FALSE, project_scope = NULL, access_token, asset_view = NULL, json_str = NULL) { - + a <- paste0(sample(1000, 1), "-") + cat(paste0(a, "-validate func ", data_type, " ", file_name, "\n")) flattenbody <- function(x) { # A form/query can only have one value per name, so take # any values that contain vectors length >1 and @@ -137,8 +138,15 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate", } if (is.null(json_str)) { - req <- httr2::request(url) - resp <- req %>% + reqs <- httr2::request(url) |> + httr2::req_retry( + max_tries = 3, + is_transient = \(reqs) httr2::resp_status(reqs) %in% c(429, 500, 503, 504) + ) |> + httr2::req_error(is_error = \(reqs) FALSE) |> + httr2::req_throttle(1) + cat(paste0(a, "-validate func requesting", unlist(reqs), "\n")) + resp <- reqs %>% httr2::req_headers(Authorization = sprintf("Bearer %s", access_token)) |> httr2::req_url_query( schema_url=schema_url, @@ -148,14 +156,11 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate", asset_view = asset_view ) |> httr2::req_body_multipart(file_name=curl::form_file(file_name)) |> - httr2::req_retry( - max_tries = 3, - is_transient = \(resp) httr2::resp_status(resp) %in% c(429, 500, 503, 504) - ) |> - httr2::req_error(is_error = \(resp) FALSE) |> httr2::req_perform() + cat(paste0(a, "-validate func response", unlist(resp), "\n")) } else { - req <- httr2::request(url) + req <- httr2::request(url) |> + httr2::req_throttle(1) resp <- req %>% httr2::req_headers(Authorization = sprintf("Bearer %s", access_token)) |> httr2::req_url_query( @@ -166,15 +171,16 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate", asset_view = asset_view, json_str = json_str ) |> - httr2::req_retry( - max_tries = 3, - is_transient = \(resp) httr2::resp_status(resp) %in% c(429, 500, 503, 504) - ) |> - httr2::req_error(is_error = \(resp) FALSE) |> + #httr2::req_retry( + # max_tries = 3, + # is_transient = \(resp) httr2::resp_status(resp) %in% c(429, 500, 503, 504) + #) |> + #httr2::req_error(is_error = \(resp) FALSE) |> httr2::req_perform() } # Format server error in a way validationResult can handle + cat(a, "-validate func response", "\n") if (httr2::resp_is_error(resp)) { return( list( @@ -243,14 +249,15 @@ model_component_requirements <- function(url="http://localhost:3001/v1/model/com schema_url, source_component, as_graph = FALSE) { - req <- httr2::request(url) - resp <- req |> + reqs <- httr2::request(url) |> + httr2::req_throttle(1) + resp <- reqs |> httr2::req_url_query( schema_url = schema_url, source_component = source_component, as_graph = as_graph ) |> - httr2::req_retry(max_tries = 3) |> + #httr2::req_retry(max_tries = 3) |> httr2::req_perform() resp |> httr2::resp_body_json()