Skip to content

Commit

Permalink
avoid chaning status of 'Done' workflows to 'Aborted'
Browse files Browse the repository at this point in the history
- #64
  • Loading branch information
mtmorgan committed Oct 5, 2022
1 parent 1176056 commit b4b09ff
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
60 changes: 52 additions & 8 deletions R/avworkflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
5 changes: 5 additions & 0 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
4 changes: 3 additions & 1 deletion man/avworkflow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b4b09ff

Please sign in to comment.