Skip to content

Commit

Permalink
terminate(all = TRUE)
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Jul 24, 2024
1 parent 365cc3f commit 349ae69
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Description: In computationally demanding analysis projects,
'clustermq' by Schubert (2019) <doi:10.1093/bioinformatics/btz284>),
and 'batchtools' by Lang, Bischl, and Surmann (2017).
<doi:10.21105/joss.00135>.
Version: 0.0.6.9002
Version: 0.0.6.9003
License: MIT + file LICENSE
URL: https://wlandau.github.io/crew.aws.batch/,
https://github.com/wlandau/crew.aws.batch
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# crew.aws.batch 0.0.6.9002 (development)
# crew.aws.batch 0.0.6.9003 (development)

* Send both cancellation and termination requests to end jobs.
* Fix launcher bug/typo where parameters were supplied to container overrides.
* Add a new `all` argument to `terminate()` in the AWS Batch monitor.

# crew.aws.batch 0.0.6

Expand Down
18 changes: 15 additions & 3 deletions R/crew_monitor_aws_batch.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,26 +183,35 @@ crew_class_monitor_aws_batch <- R6::R6Class(
#' @description Terminate one or more AWS Batch jobs.
#' @return `NULL` (invisibly).
#' @param ids Character vector with the IDs of the AWS Batch jobs
#' to terminate.
#' to terminate. Leave as `NULL` if `all` is `TRUE`.
#' @param all `TRUE` to terminate all jobs belonging to
#' the previously specified job definition. `FALSE` to terminate
#' only the job IDs given in the `ids` argument.
#' @param reason Character of length 1, natural language explaining
#' the reason the job was terminated.
#' @param verbose Logical of length 1, whether to show a progress bar
#' if the R process is interactive and `length(ids)` is greater than 1.
terminate = function(
ids,
ids = NULL,
all = FALSE,
reason = "cancelled/terminated by crew.aws.batch monitor",
verbose = TRUE
) {
# Covered in tests/interactive/jobs.R
# nocov start
crew::crew_assert(
ids,
ids %|||% "x",
is.character(.),
length(.) > 0L,
!anyNA(.),
nzchar(.),
message = "'ids' must be a valid nonempty character"
)
crew::crew_assert(
all,
isTRUE(.) || isFALSE(.),
message = "'all' must be TRUE or FALSE."
)
crew::crew_assert(
reason,
is.character(.),
Expand All @@ -213,6 +222,9 @@ crew_class_monitor_aws_batch <- R6::R6Class(
)
crew::crew_assert(verbose, isTRUE(.) || isFALSE(.))
client <- private$.client()
if (all) {
ids <- self$jobs()$id
}
progress <- progress_init(verbose = verbose, total = length(ids))
for (id in ids) {
client$cancel_job(jobId = id, reason = reason)
Expand Down
2 changes: 1 addition & 1 deletion tests/monitor/test-monitor.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ test_that("job terminate", {
message(nrow(monitor$active()))
Sys.sleep(1)
}
monitor$terminate(ids = monitor$active()$id, verbose = TRUE)
monitor$terminate(all = TRUE, verbose = TRUE)
while (nrow(monitor$active()) > 0L) {
message(paste(monitor$active()$status, collapse = " "))
Sys.sleep(5)
Expand Down

0 comments on commit 349ae69

Please sign in to comment.