Skip to content

Commit

Permalink
fix: If plumber deployment fails, handle failure gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
csgillespie committed Dec 5, 2023
1 parent cd8a282 commit ee64c65
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre"))
Description: Posit Connect Health Check. Deploys various content types to
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
2 changes: 2 additions & 0 deletions R/check_sys_deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion R/create_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
4 changes: 2 additions & 2 deletions R/deploy_pins.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 3 additions & 1 deletion R/deploy_plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
14 changes: 7 additions & 7 deletions R/deploy_quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
2 changes: 1 addition & 1 deletion R/deploy_rmd-r6.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion R/deploy_streamlit-r6.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion R/summarise_users.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 7 additions & 7 deletions inst/extdata/deploy_plumber/plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@ 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
#* @param a The first number to add
#* @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())
}

0 comments on commit ee64c65

Please sign in to comment.