Skip to content

Commit 00930ed

Browse files
makeClusterFunctionsSlurm2(): Inject runOSCommand() that defaults to runOSCommand(..., stderr = FALSE)
1 parent c104f2d commit 00930ed

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
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-9011
2+
Version: 0.20.0-9012
33
Depends:
44
R (>= 3.2.0),
55
parallelly,

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ importFrom(batchtools,makeClusterFunctionsTORQUE)
8686
importFrom(batchtools,makeRegistry)
8787
importFrom(batchtools,makeSubmitJobResult)
8888
importFrom(batchtools,removeRegistry)
89-
importFrom(batchtools,runOSCommand)
9089
importFrom(batchtools,saveRegistry)
9190
importFrom(batchtools,setJobNames)
9291
importFrom(batchtools,submitJobs)

R/makeClusterFutureSlurm2.R

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Patch Slurm cluster functions listJobsQueued() and listJobsRunning()
22
# to use `sacct` instead of `squeue`
3-
#' @importFrom batchtools assertRegistry runOSCommand
3+
#' @importFrom batchtools assertRegistry
44
#' @importFrom utils tail
55
patchClusterFunctionsSlurm2 <- function(cf) {
66
OSError <- import_from("OSError", package = "batchtools")
@@ -12,6 +12,17 @@ patchClusterFunctionsSlurm2 <- function(cf) {
1212
nodename <- env[["nodename"]]
1313
org_listJobsQueued <- env[["listJobsQueued"]]
1414

15+
## Inject runOSCommand() that defaults to runOSCommand(..., stderr = FALSE)
16+
env[["runOSCommand"]] <- function(..., stderr = FALSE) {
17+
debug <- isTRUE(getOption("future.batchtools.debug"))
18+
if (debug) {
19+
mdebugf_push("runOSCommand(..., stderr = FALSE) ...")
20+
mprint(list(args = list(..., stderr = stderr)))
21+
on.exit(mdebugf_pop())
22+
}
23+
runOSCommand(..., stderr = stderr)
24+
}
25+
1526
## Allow for a 15-minute offset in time between host and Slurm's sacct server
1627
isJobQueued <- function(reg, batch_id, since = NULL, offset = 15*60) {
1728
stopifnot(length(batch_id) == 1L, !is.na(batch_id), nzchar(batch_id))
@@ -38,6 +49,12 @@ patchClusterFunctionsSlurm2 <- function(cf) {
3849
} ## isJobQueued()
3950

4051
cf$listJobsQueued <- function(reg) {
52+
debug <- isTRUE(getOption("future.batchtools.debug"))
53+
if (debug) {
54+
mdebugf_push("[makeClusterFunctionsSlurm2()]$listJobsQueued() ...")
55+
on.exit(mdebugf_pop())
56+
}
57+
4158
batch_id <- getOption("future.batchtools.batch_id", NULL)
4259

4360
## Queued jobs according to 'squeue'

R/runOSCommand.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#' @importFrom checkmate assertCharacter assertString %??%
22
#' @importFrom stringi stri_replace_all_fixed stri_flatten
33
runOSCommand = function(sys.cmd, sys.args = character(0L), stdin = "", stdout = TRUE, stderr = TRUE, nodename = "localhost") {
4+
isLocalHost <- import_from("isLocalHost", package = "batchtools")
45
assertCharacter(sys.cmd, any.missing = FALSE, len = 1L)
56
assertCharacter(sys.args, any.missing = FALSE)
67
assertString(nodename, min.chars = 1L)
@@ -31,7 +32,3 @@ runOSCommand = function(sys.cmd, sys.args = character(0L), stdin = "", stdout =
3132

3233
return(list(sys.cmd = sys.cmd, sys.args = sys.args, exit.code = exit.code, output = output))
3334
}
34-
35-
isLocalHost = function(nodename) {
36-
is.null(nodename) || nodename %chin% c("localhost", "127.0.0.1", "::1")
37-
}

0 commit comments

Comments
 (0)