R/engineStats.R

Defines functions engineStats

Documented in engineStats

#' Returns basic statistics from this Cromwell server.
#'
#' @param x Cromwell API endpoint.
#' @param version Cromwell API Version.
#'
#' @return \code{StatsResponse} object.
#'
#' @examples
#' \dontrun{
#' host <- "http://localhost:8000"
#' engineStats(host)
#' }
#'
#' @export
engineStats <- function(x, version = "v1")
{
	url <- file.path(x, "engine", version, "stats")

	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(
		list(
			workflows = content$workflow,
			jobs = content$jobs,
			host = x
		),
		class = "StatsResponse"
	)
}
labbcb/CromwellClient documentation built on Aug. 16, 2020, 9:11 p.m.