From b408b2f38eece474ae59116821d52cf50e65b3e0 Mon Sep 17 00:00:00 2001 From: Colin Gillespie Date: Tue, 5 Dec 2023 13:41:23 +0000 Subject: [PATCH] fix: If plumber deployment fails, handle failure gracefully (#30) --- DESCRIPTION | 2 +- NEWS.md | 3 +++ R/check.R | 2 +- R/check_sys_deps.R | 2 ++ R/create_config.R | 2 +- R/deploy_pins.R | 4 ++-- R/deploy_plumber.R | 4 +++- R/deploy_quarto.R | 14 +++++++------- R/deploy_rmd-r6.R | 2 +- R/deploy_streamlit-r6.R | 2 +- R/summarise_users.R | 2 +- inst/extdata/deploy_plumber/plumber.R | 14 +++++++------- 12 files changed, 30 insertions(+), 23 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 824d128..332f14c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: audit.connect Title: Posit Connect Health Check -Version: 0.7.0 +Version: 0.7.1 Authors@R: person("Jumping", "Rivers", , "info@jumpingrivers.com", role = c("aut", "cre")) Description: Posit Connect Health Check. Deploys various content types to diff --git a/NEWS.md b/NEWS.md index 7c964f6..5e8ec71 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# audit.connect 0.7.1 _2023-12-05_ + - fix: If plumber deployment fails, handle failure gracefully + # audit.connect 0.7.0 _2023-10-18_ - feat: `audit_object |> audit.connect::sanitize()` removes personal user data - feat: Add in user URL when summarising users diff --git a/R/check.R b/R/check.R index fd7d69c..64e414b 100644 --- a/R/check.R +++ b/R/check.R @@ -25,7 +25,7 @@ check = function(server = NULL, token = NULL, check_list$audit_details = audit_details(get_server(), get_token()) check_list$server_headers = audit.base::check_server_headers(get_server()) check_list$posit_version = check_posit_version(get_server(), get_token(), - debug_level = debug_level) + debug_level = debug_level) check_list$sys_deps = check_sys_deps(debug_level = debug_level) check_list$versions = summarise_versions(get_server(), get_token()) diff --git a/R/check_sys_deps.R b/R/check_sys_deps.R index 13be38e..cb44c87 100644 --- a/R/check_sys_deps.R +++ b/R/check_sys_deps.R @@ -16,6 +16,8 @@ check_sys_deps = function(debug_level = 0:2) { content = try(setup_plumber_sys_deps_endpoint(app_dir, debug_level), silent = TRUE) if ("try-error" %in% class(content)) { cli::cli_alert_info("Can't deploy plumber end point - odd?") + cli::cli_alert_info("Check the logs on {get_server()}") + cli::cli_alert_info("In the past, it was due to a missing sodium linux dependency") return(NA) } diff --git a/R/create_config.R b/R/create_config.R index 1f09321..372e3ba 100644 --- a/R/create_config.R +++ b/R/create_config.R @@ -17,4 +17,4 @@ #' * error: if a config file exists, raise an error #' @export create_config = audit.base::create_config(file = "config-uat-rsc.yml", - pkg_name = "audit.connect") + pkg_name = "audit.connect") diff --git a/R/deploy_pins.R b/R/deploy_pins.R index df72316..8e8abd1 100644 --- a/R/deploy_pins.R +++ b/R/deploy_pins.R @@ -1,8 +1,8 @@ deploy_pins = function(debug_level) { suppress = get_suppress(debug_level) board = suppress(pins::board_connect(auth = "manual", versioned = TRUE, - server = get_server(), - key = get_token())) + server = get_server(), + key = get_token())) tmp_env = new.env() utils::data("mtcars", package = "datasets", envir = tmp_env) diff --git a/R/deploy_plumber.R b/R/deploy_plumber.R index 99e5ec3..2689067 100644 --- a/R/deploy_plumber.R +++ b/R/deploy_plumber.R @@ -25,6 +25,8 @@ deploy_plumber = function(plumber_dir, debug_level) { cleanup_plumber = function(bundle_dir, content, debug_level) { suppress = get_suppress(debug_level) if (debug_level == 2) return(NULL) - if (exists("content")) suppress(connectapi::content_delete(content, force = TRUE)) + if (exists("content") && "Connect" %in% class(content)) { + suppress(connectapi::content_delete(content, force = TRUE)) + } fs::dir_delete(bundle_dir) } diff --git a/R/deploy_quarto.R b/R/deploy_quarto.R index c1414fd..4051972 100644 --- a/R/deploy_quarto.R +++ b/R/deploy_quarto.R @@ -9,13 +9,13 @@ deploy_quarto = function(quarto_dir, account = NULL, debug_level = debug_level) # quarto uses rsconnect::accounts. So, looks up the server in list of accounts if (is.null(account)) account = get_account() has_deployed = suppress(quarto::quarto_publish_doc(file.path(tmp_dir, "index.qmd"), - render = "server", - title = title, - server = get_server(clean = TRUE), - account = account, - launch.browser = FALSE, - forceUpdate = TRUE, - logLevel = "quiet")) + render = "server", + title = title, + server = get_server(clean = TRUE), + account = account, + launch.browser = FALSE, + forceUpdate = TRUE, + logLevel = "quiet")) return(invisible(has_deployed)) } diff --git a/R/deploy_rmd-r6.R b/R/deploy_rmd-r6.R index 3d26fe7..256e7dd 100644 --- a/R/deploy_rmd-r6.R +++ b/R/deploy_rmd-r6.R @@ -12,7 +12,7 @@ for (type in types) { public = list( check = function(debug_level) { rmd_dir = system.file("extdata", private$group, private$short, - package = "audit.base", mustWork = TRUE) + package = "audit.base", mustWork = TRUE) private$checker( deploy_app(rmd_dir, debug_level = debug_level)) diff --git a/R/deploy_streamlit-r6.R b/R/deploy_streamlit-r6.R index 37f24a7..0ee14fa 100644 --- a/R/deploy_streamlit-r6.R +++ b/R/deploy_streamlit-r6.R @@ -14,7 +14,7 @@ check_deploy_python_streamlit = R6::R6Class( return(invisible(NULL)) } python_dir = system.file("extdata", private$group, private$short, - package = "audit.connect", mustWork = TRUE) + package = "audit.connect", mustWork = TRUE) private$checker(deploy_python(python_dir, python_files = "app.py", rsconnect_type = "streamlit", diff --git a/R/summarise_users.R b/R/summarise_users.R index 5136746..376a57b 100644 --- a/R/summarise_users.R +++ b/R/summarise_users.R @@ -44,7 +44,7 @@ print_audit_user_apps = function(client, debug_level) { suppress = get_suppress(debug_level) apps = suppress(connectapi::cache_apps(client)) # Remove any api keys; don't need or want them - apps = purrr::map(apps, ~{.x$EnvironmentJson = NULL; .x}) + apps = purrr::map(apps, ~{.x$EnvironmentJson = NULL; .x}) # nolint app_creators = purrr::map_df(apps, ~dplyr::tibble(owner = .x[["owner_username"]], locked = .x$owner_locked)) diff --git a/inst/extdata/deploy_plumber/plumber.R b/inst/extdata/deploy_plumber/plumber.R index a41042f..c740d41 100644 --- a/inst/extdata/deploy_plumber/plumber.R +++ b/inst/extdata/deploy_plumber/plumber.R @@ -16,15 +16,15 @@ library(plumber) #* @param msg The message to echo #* @get /echo function(msg = "") { - list(msg = paste0("The message is: '", msg, "'")) + list(msg = paste0("The message is: '", msg, "'")) } #* Plot a histogram #* @serializer png #* @get /plot function() { - rand = rnorm(100) - hist(rand) + rand = rnorm(100) + hist(rand) } #* Return the sum of two numbers @@ -32,13 +32,13 @@ function() { #* @param b The second number to add #* @post /sum function(a, b) { - as.numeric(a) + as.numeric(b) + as.numeric(a) + as.numeric(b) } # Programmatically alter your API #* @plumber function(pr) { - pr %>% - # Overwrite the default serializer to return unboxed JSON - pr_set_serializer(serializer_unboxed_json()) + pr %>% + # Overwrite the default serializer to return unboxed JSON + pr_set_serializer(serializer_unboxed_json()) }