R/status.R

Defines functions status.WorkflowIdAndStatus status.character status

Documented in status status.character status.WorkflowIdAndStatus

#' Get status of a workflow
#'
#' Retrieves the current state for a workflow
#'
#' @param x Cromwell API endpoint of \code{WorkflowIdAndStatus} object.
#' @param ... not used
#'
#' @return \code{WorkflowIdAndStatus} object containing status and id.
#'
#' @examples
#' \dontrun{
#' host <- "http://localhost:8000"
#' workflow <- system.file("extdata/workflow.wdl", package = "CromwellClient")
#' inputs <- system.file("extdata/inputs.json", package = "CromwellClient")
#' job <- submit(host, workflow, inputs)
#' status(job)
#' }
#'
#' @rdname status
#' @export
status <- function(x, ...)
{
	UseMethod("status", x)
}

#' @param id A workflow ID.
#' @param version Cromwell API Version.
#'
#' @rdname status
#' @export
status.character <- function(x, id, version = "v1", ...)
{
	url <- file.path(x, "api/workflows", version, id, "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(
		list(
			id = content$id,
			status = content$status,
			host = x,
			version = version
		),
		class = "WorkflowIdAndStatus"
	)
}

#' @rdname status
#' @export
status.WorkflowIdAndStatus <- function(x, ...)
{
	status(x = x$host, id = x$id, version = x$version)
}
labbcb/CromwellClient documentation built on Aug. 16, 2020, 9:11 p.m.