R/abort.R

Defines functions abort.WorkflowIdAndStatus abort.character abort

Documented in abort abort.character abort.WorkflowIdAndStatus

#' Abort a running workflow
#'
#' Request Cromwell to abort a running workflow. For instance this might be
#' necessary in cases where you have submitted a workflow with incorrect inputs
#' or no longer need the results. Cromwell will make a best effort attempt to
#' immediately halt any currently running jobs from this 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)
#' abort(job)
#' }
#'
#' @rdname abort
#' @export
abort <- function(x, ...)
{
	UseMethod("abort", x)
}

#' @param id A workflow ID.
#' @param version Cromwell API Version.
#'
#' @rdname abort
#' @export
abort.character <- function(x, id, version = "v1", ...)
{
	url <- file.path(x, "api/workflows", version, id, "abort")

	response <- httr::POST(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 abort
#' @export
abort.WorkflowIdAndStatus <- function(x, ...)
{
	abort(x$host, id = x$id, version = x$version)
}
labbcb/CromwellClient documentation built on Aug. 16, 2020, 9:11 p.m.