Skip to content

Commit 84cabe9

Browse files
Added backend argument 'delete'; removed argument 'future.delete'
1 parent f3d0582 commit 84cabe9

31 files changed

+171
-65
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future.batchtools
2-
Version: 0.12.2-9963
2+
Version: 0.12.2-9964
33
Depends:
44
R (>= 3.2.0),
55
parallelly,

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
* **future.batchtools** now implements the FutureBackend API
66
introduced in **future** 1.40.0 (2025-04-10).
77

8+
* Removed option `future.delete`. To control whether batchtools
9+
futures should be deleted from the file system, see future backend
10+
argument `delete`, which defaults to `"on-success"`, but can also
11+
be set to `"never"` and `"always"`.
12+
813
## New Features
914

1015
* Most types of batchtools future can now be interrupted, including

R/BatchtoolsFutureBackend-class.R

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
#' job-script template as variable `resources`. See Section 'Resources'
3131
#' in [batchtools::submitJobs()] more details.
3232
#'
33+
#' @param delete Controls if and when the batchtools job registry folder is
34+
#' deleted.
35+
#' If `"on-success"` (default), it is deleted if the future was resolved
36+
#' successfully _and_ the expression did not produce an error.
37+
#' If `"never"`, then it is never deleted.
38+
#' If `"always"`, then it is always deleted.
39+
#'
3340
#' @param \ldots Not used.
3441
#'
3542
#' @return A [future::FutureBackend] object of class BatchtoolsFutureBackend
@@ -46,6 +53,7 @@ BatchtoolsFutureBackend <- function(
4653
registry = list(),
4754
conf.file = findConfFile(),
4855
interrupts = TRUE,
56+
delete = "on-success",
4957
...) {
5058
assert_no_positional_args_but_first()
5159

@@ -75,7 +83,9 @@ BatchtoolsFutureBackend <- function(
7583
}
7684

7785
stop_if_not(is.list(resources))
78-
86+
stop_if_not(is.character(delete))
87+
delete <- match.arg(delete, choices = c("on-success", "never", "always"))
88+
7989
core <- FutureBackend(
8090
reg = "workers-batchtools",
8191
workers = workers,
@@ -85,6 +95,7 @@ BatchtoolsFutureBackend <- function(
8595
registry = registry,
8696
finalize = finalize,
8797
interrupts = interrupts,
98+
delete = delete,
8899
future.wait.timeout = getOption("future.wait.timeout", 30 * 24 * 60 * 60),
89100
future.wait.interval = getOption("future.wait.interval", 0.01),
90101
future.wait.alpha = getOption("future.wait.alpha", 1.01),
@@ -200,6 +211,7 @@ launchFuture.BatchtoolsFutureBackend <- local({
200211
mprint(list(config = config))
201212
}
202213
future[["config"]] <- config
214+
future[["delete"]] <- backend[["delete"]]
203215

204216
## Register finalizer?
205217
if (backend[["finalize"]]) future <- add_finalizer(future)
@@ -309,12 +321,14 @@ launchFuture.BatchtoolsFutureBackend <- local({
309321
submitJobs(reg = reg, ids = jobid, resources = resources)
310322
})
311323
}, error = function(ex) {
324+
path <- reg$file.dir
312325
msg <- conditionMessage(ex)
313326
label <- sQuoteLabel(future)
314327
msg <- sprintf("Failed to submit %s (%s). The reason was: %s", class(future)[1], label, msg)
315328
info <- capture.output(str(resources))
316329
info <- paste(info, collapse = "\n")
317-
msg <- sprintf("%s\nTROUBLESHOOTING INFORMATION:\nbatchtools::submitJobs() was called with the following 'resources' argument:\n%s\n", msg, info)
330+
msg <- sprintf("%s\nTROUBLESHOOTING INFORMATION:\nbatchtools::submitJobs() was called with the following 'resources' argument:\n%s", msg, info)
331+
msg <- sprintf("%s\nDETAILS:\nThe batchtools registry path: %s", msg, sQuote(path))
318332
stop(FutureLaunchError(msg, future = future))
319333
})
320334

@@ -944,11 +958,12 @@ delete.BatchtoolsFuture <- function(future,
944958

945959
## To simplify post mortem troubleshooting in non-interactive sessions,
946960
## should the batchtools registry files be removed or not?
961+
delete <- future[["delete"]]
947962
if (debug) {
948-
mdebugf("delete(): Option 'future.delete = %s",
949-
sQuote(getOption("future.delete", "<NULL>")))
963+
mdebugf("delete(): Future backend argument 'delete' is %s", sQuote(delete))
950964
}
951-
if (!getOption("future.delete", interactive())) {
965+
966+
if (delete != "never") {
952967
status <- status(future)
953968
res <- future$result
954969
if (inherits(res, "FutureResult")) {
@@ -959,16 +974,18 @@ delete.BatchtoolsFuture <- function(future,
959974
paste(sQuote(status), collapse = ", "))
960975
}
961976
if (any(c("error", "expired") %in% status)) {
962-
msg <- sprintf("Will not remove batchtools registry, because the status of the batchtools was %s and option 'future.delete' is FALSE or running in an interactive session: %s", paste(sQuote(status), collapse = ", "), sQuote(path)) #nolint
963-
if (debug) mdebugf("delete(): %s", msg)
964-
warning(msg)
965-
return(invisible(FALSE))
977+
if (delete == "on-success") {
978+
msg <- sprintf("Will not remove batchtools registry, because the status of the batchtools was %s and future backend argument 'delete' is %s: %s", paste(sQuote(status), collapse = ", "), sQuote(delete), sQuote(path)) #nolint
979+
if (debug) mdebugf("delete(): %s", msg)
980+
warning(msg)
981+
return(invisible(FALSE))
982+
}
966983
}
967984
}
968985

969986
## Have user disabled deletions?
970-
if (!getOption("future.delete", TRUE)) {
971-
msg <- sprintf("Option 'future.delete' is FALSE - will not delete batchtools registry: %s", sQuote(path))
987+
if (delete == "never") {
988+
msg <- sprintf("Future backend argument 'delete' is %s - will not delete batchtools registry: %s", sQuote(delete), sQuote(path))
972989
if (debug) mdebugf("delete(): %s", msg)
973990
return(invisible(FALSE))
974991
}

R/BatchtoolsTemplateFutureBackend-class.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#' @importFrom batchtools makeClusterFunctionsSlurm
4848
#' @importFrom batchtools makeClusterFunctionsTORQUE
4949
#' @export
50-
BatchtoolsTemplateFutureBackend <- function(type, scheduler.latency = 1.0, fs.latency = 65.0, resources = list(), template = NULL, makeClusterFunctions = NULL, workers = getOption("future.batchtools.workers", default = 100L), ...) {
50+
BatchtoolsTemplateFutureBackend <- function(type, scheduler.latency = 1.0, fs.latency = 65.0, resources = list(), delete = "on-success", template = NULL, makeClusterFunctions = NULL, workers = getOption("future.batchtools.workers", default = 100L), ...) {
5151
assert_no_positional_args_but_first()
5252
stop_if_not(
5353
is.character(type),
@@ -105,6 +105,7 @@ BatchtoolsTemplateFutureBackend <- function(type, scheduler.latency = 1.0, fs.la
105105
args <- dotdotdot
106106
args[["cluster.functions"]] <- cluster.functions
107107
args[["workers"]] <- workers
108+
args[["delete"]] <- delete
108109

109110
core <- do.call(BatchtoolsMultiprocessFutureBackend, args = args)
110111

R/batchtools_bash.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ BatchtoolsBashFutureBackend <- function(..., template = "bash", fs.latency = 0.0
7676
#' print(info)
7777
#'
7878
#' @export
79-
batchtools_bash <- function(..., template = "bash", fs.latency = 0.0, resources = list()) {
79+
batchtools_bash <- function(..., template = "bash", fs.latency = 0.0, resources = list(), delete = "on-success") {
8080
stop("INTERNAL ERROR: The future.batchtools::batchtools_bash() must never be called directly")
8181
}
8282
class(batchtools_bash) <- c(

R/batchtools_interactive.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ BatchtoolsInteractiveFutureBackend <- function(fs.latency = 0.0, ...) {
6262
#' @inheritParams BatchtoolsInteractiveFutureBackend
6363
#'
6464
#' @export
65-
batchtools_interactive <- function(..., fs.latency = 0.0) {
65+
batchtools_interactive <- function(..., fs.latency = 0.0, delete = "on-success") {
6666
stop("INTERNAL ERROR: The future.batchtools::batchtools_interactive() must never be called directly")
6767
}
6868
class(batchtools_interactive) <- c(

R/batchtools_local.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ BatchtoolsLocalFutureBackend <- function(fs.latency = 0.0, ...) {
9292
#' print(info)
9393
#'
9494
#' @export
95-
batchtools_local <- function(..., fs.latency = 0.0) {
95+
batchtools_local <- function(..., fs.latency = 0.0, delete = "on-success") {
9696
stop("INTERNAL ERROR: The future.batchtools::batchtools_local() must never be called directly")
9797
}
9898
class(batchtools_local) <- c(

R/batchtools_lsf.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ BatchtoolsLsfFutureBackend <- function(...) {
5959
#' * <https://en.wikipedia.org/wiki/IBM_Spectrum_LSF>
6060
#'
6161
#' @export
62-
batchtools_lsf <- function(..., template = "lsf", scheduler.latency = 1.0, fs.latency = 65.0, resources = list(), workers = getOption("future.batchtools.workers", default = 100L)) {
62+
batchtools_lsf <- function(..., template = "lsf", scheduler.latency = 1.0, fs.latency = 65.0, resources = list(), delete = "on-success", workers = getOption("future.batchtools.workers", default = 100L)) {
6363
stop("INTERNAL ERROR: The future.batchtools::batchtools_lsf() must never be called directly")
6464
}
6565
class(batchtools_lsf) <- c(

R/batchtools_multicore.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#' @importFrom parallelly availableCores supportsMulticore
3232
#' @importFrom tools pskill
3333
#' @export
34-
BatchtoolsMulticoreFutureBackend <- function(workers = availableCores(constraints = "multicore"), fs.latency = 0.0, ...) {
34+
BatchtoolsMulticoreFutureBackend <- function(workers = availableCores(constraints = "multicore"), fs.latency = 0.0, delete = "on-success", ...) {
3535
assert_no_positional_args_but_first()
3636

3737
if (is.function(workers)) workers <- workers()
@@ -103,7 +103,7 @@ BatchtoolsMulticoreFutureBackend <- function(workers = availableCores(constraint
103103
#' print(info)
104104
#'
105105
#' @export
106-
batchtools_multicore <- function(..., workers = availableCores(constraints = "multicore"), fs.latency = 0.0) {
106+
batchtools_multicore <- function(..., workers = availableCores(constraints = "multicore"), fs.latency = 0.0, delete = "on-success") {
107107
stop("INTERNAL ERROR: The future.batchtools::batchtools_multicore() must never be called directly")
108108
}
109109
class(batchtools_multicore) <- c(

R/batchtools_openlava.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ BatchtoolsOpenLavaFutureBackend <- function(...) {
5959
#' * <https://en.wikipedia.org/wiki/OpenLava>
6060
#'
6161
#' @export
62-
batchtools_openlava <- function(..., template = "openlava", scheduler.latency = 1.0, fs.latency = 65.0, resources = list(), workers = getOption("future.batchtools.workers", default = 100L)) {
62+
batchtools_openlava <- function(..., template = "openlava", scheduler.latency = 1.0, fs.latency = 65.0, resources = list(), delete = "on-success", workers = getOption("future.batchtools.workers", default = 100L)) {
6363
stop("INTERNAL ERROR: The future.batchtools::batchtools_openlava() must never be called directly")
6464
}
6565
class(batchtools_openlava) <- c(

0 commit comments

Comments
 (0)