Skip to content

Commit 363c159

Browse files
tcuttstcutts
authored andcommitted
Added support for the --only-job-state option for squeue
Signed-off-by: tcutts <tim.cutts@astrazeneca.com>
1 parent 7b664ce commit 363c159

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

modules/nextflow/src/main/groovy/nextflow/executor/SlurmExecutor.groovy

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class SlurmExecutor extends AbstractGridExecutor implements TaskArrayExecutor {
4040
static private Pattern SUBMIT_REGEX = ~/Submitted batch job (\d+)/
4141

4242
private boolean perCpuMemAllocation
43+
private boolean onlyJobState
4344

4445
private boolean hasSignalOpt(TaskConfig config) {
4546
final opts = config.getClusterOptionsAsString()
@@ -157,7 +158,13 @@ class SlurmExecutor extends AbstractGridExecutor implements TaskArrayExecutor {
157158
@Override
158159
protected List<String> queueStatusCommand(Object queue) {
159160

160-
final result = ['squeue','--noheader','-o','%i %t', '-t', 'all']
161+
final result = ['squeue','--noheader', '-o','%i %t', '-t', 'all']
162+
163+
if (onlyJobState) {
164+
result << '--only-job-state'
165+
// -p and -u cannot be used with --only-job-state
166+
return result
167+
}
161168

162169
if( queue )
163170
result << '-p' << queue.toString()
@@ -213,6 +220,7 @@ class SlurmExecutor extends AbstractGridExecutor implements TaskArrayExecutor {
213220
void register() {
214221
super.register()
215222
perCpuMemAllocation = config.getExecConfigProp(name, 'perCpuMemAllocation', false)
223+
onlyJobState = config.getExecConfigProp(name, 'onlyJobState', false)
216224
}
217225

218226
@Override

modules/nextflow/src/test/groovy/nextflow/executor/SlurmExecutorTest.groovy

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,54 @@ class SlurmExecutorTest extends Specification {
312312
exec.queueStatusCommand('xxx') == ['squeue','--noheader','-o','%i %t','-t','all','-p','xxx','-u', usr]
313313
}
314314

315+
def 'should use onlyJobState option and omit queue and user' () {
316+
given:
317+
def exec = createExecutor()
318+
exec.@onlyJobState = true
319+
320+
when:
321+
def result = exec.queueStatusCommand(null)
322+
323+
then:
324+
result == ['squeue','--noheader','-o','%i %t','-t','all','--only-job-state']
325+
!result.contains('-u')
326+
!result.contains('-p')
327+
}
328+
329+
def 'should use onlyJobState option and ignore queue parameter' () {
330+
given:
331+
def exec = createExecutor()
332+
exec.@onlyJobState = true
333+
334+
when:
335+
def result = exec.queueStatusCommand('myqueue')
336+
337+
then:
338+
result == ['squeue','--noheader','-o','%i %t','-t','all','--only-job-state']
339+
!result.contains('-p')
340+
!result.contains('myqueue')
341+
!result.contains('-u')
342+
}
343+
344+
def 'should include queue and user when onlyJobState is disabled' () {
345+
given:
346+
def exec = createExecutor()
347+
exec.@onlyJobState = false
348+
349+
when:
350+
def usr = System.getProperty('user.name')
351+
def resultNoQueue = exec.queueStatusCommand(null)
352+
def resultWithQueue = exec.queueStatusCommand('myqueue')
353+
354+
then:
355+
resultNoQueue == ['squeue','--noheader','-o','%i %t','-t','all','-u', usr]
356+
!resultNoQueue.contains('--only-job-state')
357+
358+
and:
359+
resultWithQueue == ['squeue','--noheader','-o','%i %t','-t','all','-p','myqueue','-u', usr]
360+
!resultWithQueue.contains('--only-job-state')
361+
}
362+
315363
def 'should get array index name and start' () {
316364
given:
317365
def executor = createExecutor()

0 commit comments

Comments
 (0)