diff --git a/R/avworkflow.R b/R/avworkflow.R index 9623ff8..dee7a1e 100644 --- a/R/avworkflow.R +++ b/R/avworkflow.R @@ -444,7 +444,9 @@ avworkflow_run <- #' @description `avworkflow_stop()` stops the most recently submitted workflow #' jub from running. #' -#' @return `avworkflow_stop()` returns NULL, invisibly. +#' @return `avworkflow_stop()` returns (invisibly) `TRUE` on +#' successfully requesting that the workflow stop, `FALSE` if the +#' workflow is already aborting, aborted, or done. #' #' @examples #' \dontrun{ @@ -473,19 +475,61 @@ avworkflow_stop <- if (dry) { message( - "'avworkflow_stop()' arguments validated, use 'dry = FALSE' ", - "to stop ", paste0(namespace, "/", name), " ", - "submissionId = ", submissionId + .pretty_text( + "'avworkflow_stop()' arguments validated, use 'dry = FALSE'", + "to stop the submission" + ), "\n", + " namespace: ", namespace, "\n", + " name: ", name, "\n", + " submissionId: ", submissionId, "\n" ) - return(invisible(NULL)) + return(invisible(FALSE)) } - abort_workflow <- Rawls()$abortSubmission( + terra <- Terra() + + ## only change status of submitted / running workflows. In + ## particular do not change the status of 'Done' workflows to + ## 'Aborted'. https://github.com/Bioconductor/AnVIL/issues/64 + response <- terra$monitorSubmission( workspaceNamespace = namespace, workspaceName = name, submissionId = submissionId) + .avstop_for_status(response, "avworkflow_stop (current status)") + current_status <- content(response, encoding = "UTF-8")$status + WORKFLOW_STATUS_ENUM <- c("Aborting", "Aborted", "Done") + if (current_status %in% WORKFLOW_STATUS_ENUM) { + message( + .pretty_text( + "'avworkflow_stop()' will not change the status of workflows", + "that are already aborting, aborted, or done" + ), "\n", + " namespace: ", namespace, "\n", + " name: ", name, "\n", + " submissionId: ", submissionId, "\n", + " current status: ", current_status + ) + return(invisible(FALSE)) + } - .avstop_for_status(abort_workflow, "avworkflow_stop") + if (dry) { + message( + .pretty_text( + "'avworkflow_stop()' arguments validated, use 'dry = FALSE'", + "to stop the submission" + ), "\n", + " namespace: ", namespace, "\n", + " name: ", name, "\n", + " submissionId: ", submissionId, "\n" + ) + return(invisible(FALSE)) + } + + abort_workflow <- terra$abortSubmission( + workspaceNamespace = namespace, + workspaceName = name, + submissionId = submissionId) + .avstop_for_status(abort_workflow, "avworkflow_stop (abort workflow)") - invisible(NULL) + invisible(TRUE) } diff --git a/R/utilities.R b/R/utilities.R index 45d4165..6622df3 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -68,3 +68,8 @@ paste0(pad, "# ... with ", len, " more elements") ), collapse = "\n") } + +.pretty_text <- function(..., indent = 0L, exdent = 0L) { + text <- paste(..., collapse = " ") + paste(strwrap(text, indent = indent, exdent = exdent), collapse = "\n") +} diff --git a/man/avworkflow.Rd b/man/avworkflow.Rd index d558a74..8217a12 100644 --- a/man/avworkflow.Rd +++ b/man/avworkflow.Rd @@ -135,7 +135,9 @@ name and bucket path of files to be synchronized. \code{avworkflow_run()} returns \code{config}, invisibly. -\code{avworkflow_stop()} returns NULL, invisibly. +\code{avworkflow_stop()} returns (invisibly) \code{TRUE} on +successfully requesting that the workflow stop, \code{FALSE} if the +workflow is already aborting, aborted, or done. } \description{ \code{avworkflows()} returns a tibble summarizing available