Skip to content

Commit 6c9fb97

Browse files
Use the 'submitted' state, if 'future' supports it
1 parent 9c107f2 commit 6c9fb97

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ importFrom(stringi,stri_replace_all_fixed)
117117
importFrom(tools,pskill)
118118
importFrom(utils,capture.output)
119119
importFrom(utils,file_test)
120+
importFrom(utils,packageVersion)
120121
importFrom(utils,sessionInfo)
121122
importFrom(utils,str)
122123
importFrom(utils,tail)

R/BatchtoolsFutureBackend-class.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ launchFuture.BatchtoolsFutureBackend <- local({
361361
if (debug) mdebugf("Launched future #%d", jobid$job.id)
362362

363363
future[["submitted_on"]] <- submitted_on
364-
future[["state"]] <- "running"
364+
365+
## Until future (> 1.67.0) is on CRAN
366+
future[["state"]] <- if (futureSupportsStateSubmitted()) "submitted" else "running"
365367

366368
## 6. Reserve worker for future
367369
registerFuture(future)
@@ -595,7 +597,15 @@ status <- function(future, ...) {
595597
finished <- function(future, ...) {
596598
status <- status(future)
597599
if (is_na(status)) return(NA)
598-
any(c("finished", "error", "expired") %in% status)
600+
if (any(c("finished", "error", "expired") %in% status)) {
601+
return(TRUE)
602+
}
603+
604+
if (future[["state"]] == "submitted" && "started" %in% status) {
605+
future[["state"]] <- "running"
606+
}
607+
608+
FALSE
599609
}
600610

601611

R/utils.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,13 @@ assert_no_positional_args_but_first <- function(call = sys.call(sys.parent())) {
198198
stopf("Function %s() requires that all arguments beyond the first one are passed by name and not by position: %s", as.character(call[[1L]]), deparse(call, width.cutoff = 100L))
199199
}
200200
}
201+
202+
203+
#' @importFrom utils packageVersion
204+
futureSupportsStateSubmitted <- local({
205+
.value <- NA
206+
function() {
207+
if (is.na(.value)) .value <<- (packageVersion("future") > "1.67.0")
208+
.value
209+
}
210+
})

0 commit comments

Comments
 (0)