Skip to content

Commit 6292b80

Browse files
Record submission time, which is used when querying Slurm's 'sacct'
1 parent aa44243 commit 6292b80

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
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.20.0-9005
2+
Version: 0.20.0-9006
33
Depends:
44
R (>= 3.2.0),
55
parallelly,

R/BatchtoolsFutureBackend-class.R

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ launchFuture.BatchtoolsFutureBackend <- local({
325325
resources <- backend[["resources"]]
326326
config[["resources"]] <- resources
327327
future[["config"]] <- config
328-
328+
submitted_on <- Sys.time()
329+
329330
## WORKAROUND: batchtools::submitJobs() updates the RNG state,
330331
## which we must make sure to undo.
331332
tryCatch({
@@ -343,9 +344,10 @@ launchFuture.BatchtoolsFutureBackend <- local({
343344
msg <- sprintf("%s\nDETAILS:\nThe batchtools registry path: %s", msg, sQuote(path))
344345
stop(FutureLaunchError(msg, future = future))
345346
})
346-
347+
347348
if (debug) mdebugf("Launched future #%d", jobid$job.id)
348349

350+
future[["submitted_on"]] <- submitted_on
349351
future[["state"]] <- "running"
350352

351353
## 6. Reserve worker for future
@@ -540,8 +542,14 @@ status <- function(future, ...) {
540542
batch_id <- reg[["status"]][["batch.id"]]
541543
## Pass this to cluster functions listJobsQueued() and listJobsRunning()
542544
## via an R option, because we cannot pass as an argument.
543-
options(future.batchtools.batch_id = batch_id)
544-
on.exit(options(future.batchtools.batch_id = NULL), add = TRUE)
545+
options(
546+
future.batchtools.batch_id = batch_id,
547+
future.batchtools.submitted_on = future[["submitted_on"]]
548+
)
549+
on.exit(options(
550+
future.batchtools.batch_id = NULL,
551+
future.batchtools.submitted_on = NULL
552+
), add = TRUE)
545553

546554
status <- get_status(reg = reg, ids = jobid)
547555
status <- (unlist(status) == 1L)

R/batchtools_slurm.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,13 @@ patchClusterFunctionsSlurm2 <- function(cf) {
213213
getClusters <- env[["getClusters"]]
214214
nodename <- env[["nodename"]]
215215
org_listJobsQueued <- env[["listJobsQueued"]]
216-
217-
isJobQueued <- function(reg, batch_id) {
216+
217+
isJobQueued <- function(reg, batch_id, since = NULL) {
218218
stopifnot(length(batch_id) == 1L, !is.na(batch_id), nzchar(batch_id))
219+
stopifnot(is.null(since) || inherits(since, "POSIXct"))
219220

220221
## FIXME: Add also --starttime=<start time>, because 'sacct' only returns jobs ran today
221-
args <- c("--user=$USER", "--noheader", "--parsable2", "--allocations", "--format=State", sprintf("--jobs=%s", batch_id))
222+
args <- c("--user=$USER", "--noheader", "--parsable2", "--allocations", "--format=State", sprintf("--jobs=%s", batch_id), sprintf("--start-time=%s", format(since - 15*60, format = "%FT%T"))) ## Allow for 15-min time offsets
222223
clusters <- getClusters(reg)
223224
if (length(clusters) > 0) {
224225
args <- c(args, sprintf("--clusters=%s", clusters))
@@ -252,7 +253,10 @@ patchClusterFunctionsSlurm2 <- function(cf) {
252253
}
253254

254255
## Ask 'sacct' it if is PENDING or REQUEUED
255-
if (isJobQueued(reg, batch_id)) jobs <- as.character(batch_id)
256+
submitted_on <- getOption("future.batchtools.submitted_on", NULL)
257+
if (isJobQueued(reg, batch_id, since = submitted_on)) {
258+
jobs <- as.character(batch_id)
259+
}
256260

257261
jobs
258262
}

0 commit comments

Comments
 (0)