diff --git a/R/clusterFunctionsSLURM.R b/R/clusterFunctionsSLURM.R index d3432f0..dfafaa4 100644 --- a/R/clusterFunctionsSLURM.R +++ b/R/clusterFunctionsSLURM.R @@ -19,10 +19,23 @@ #' @template arg_template #' @template arg_list_jobs_cmd #' @template ret_cf +#' @param list.job.line.skip [\code{integer(1)}]\cr +#' Change how many lines of the job list should be skipped. Can be useful if \code{squeue} is giving +#' additional output. +#' @param cluster.name [\code{character(1)}]\cr +#' If an additional cluster name has to be specified for listing or deleting jobs it can be +#' supplied with this argument. it will be added as \code{--clusters=cluster.name} for SLURM. #' @family clusterFunctions #' @export -makeClusterFunctionsSLURM = function(template.file, list.jobs.cmd = c("squeue", "-h", "-o %i", "-u $USER")) { +makeClusterFunctionsSLURM = function(template.file, list.jobs.cmd = c("squeue", "-h", "-o %i", "-u $USER"), + list.job.line.skip = 0L, cluster.name = NULL) { + + if (!is.null(cluster.name)) { + assertString(cluster.name) + list.jobs.cmd = append(list.jobs.cmd, paste0("--clusters=", cluster.name)) + } assertCharacter(list.jobs.cmd, min.len = 1L, any.missing = FALSE) + assertCount(list.job.line.skip) template = cfReadBrewTemplate(template.file) submitJob = function(conf, reg, job.name, rscript, log.file, job.dir, resources, arrayjobs) { @@ -45,12 +58,22 @@ makeClusterFunctionsSLURM = function(template.file, list.jobs.cmd = c("squeue", } killJob = function(conf, reg, batch.job.id) { + + + if (!is.null(cluster.name)) { + cfKillBatchJob("scancel",paste0("--clusters=", cluster.name, " ", batch.job.id)) + } cfKillBatchJob("scancel", batch.job.id) } listJobs = function(conf, reg) { # Result is lines of fully quantified batch.job.ids jids = runOSCommandLinux(list.jobs.cmd[1L], list.jobs.cmd[-1L])$output + # if squeue returns additional information (like cluster name), one or more + # lines can be omitted + if (list.job.line.skip > 0L) { + jids = jids[-seq_len(list.job.line.skip)] + } stri_extract_first_regex(jids, "[0-9]+") } diff --git a/man/makeClusterFunctionsSLURM.Rd b/man/makeClusterFunctionsSLURM.Rd index 62a6966..f09f1b3 100644 --- a/man/makeClusterFunctionsSLURM.Rd +++ b/man/makeClusterFunctionsSLURM.Rd @@ -5,7 +5,7 @@ \title{Create cluster functions for SLURM-based systems.} \usage{ makeClusterFunctionsSLURM(template.file, list.jobs.cmd = c("squeue", "-h", - "-o \%i", "-u $USER")) + "-o \%i", "-u $USER"), list.job.line.skip = 0L, cluster.name) } \arguments{ \item{template.file}{[\code{character(1)}]\cr @@ -15,6 +15,14 @@ Path to a brew template file that is used for the PBS job file.} Change default system command / options to list jobs. The first entry is the command, the following the options. See \code{\link[BBmisc]{system3}}.} + +\item{list.job.line.skip}{[\code{integer(1)}]\cr +Change how many lines of the job list should be skipped. Can be useful if \code{squeue} is giving +additional output.} + +\item{cluster.name}{[\code{character(1)}]\cr +If an additional cluster name has to be specified for listing or deleting jobs it can be +supplied with this argument. it will be added as \code{--clusters=cluster.name} for SLURM.} } \value{ [\code{\link{ClusterFunctions}}].