R/engineStatus.R

Defines functions engineStatus

Documented in engineStatus

#' Return the current health status of any monitored subsystems
#'
#' @param x Cromwell API endpoint.
#' @param version Cromwell API Version.
#'
#' @return \code{StatusReponse} object.
#'
#' @examples
#' \dontrun{
#' host <- "http://localhost:8000"
#' engineStatus(host)
#' }
#'
#' @export
engineStatus <- function(x, version = "v1")
{
	url <- file.path(x, "engine", version, "status")

	response <- httr::GET(url, cromwellAgent())

	if (httr::http_error(response)) {
		stop(paste0("Cromwell API request failed.
			Code: ", httr::status_code(response), "
			Message: ", jsonlite::fromJSON(httr::content(response, "text"))$message), call. = FALSE)
	}

	if (httr::http_type(response) != "application/json") {
		stop("API did not return json", call. = FALSE)
	}

	content <- jsonlite::fromJSON(httr::content(response, "text"))
	structure(
		c(list(
			host = x,
			version = version
		), content),
		class = "StatusResponse"
	)
}
labbcb/CromwellClient documentation built on Aug. 16, 2020, 9:11 p.m.