Skip to content

Commit 982a2ac

Browse files
committed
add priority directive in processors
Signed-off-by: Jorge Aguilera <[email protected]>
1 parent 0fd345f commit 982a2ac

File tree

6 files changed

+51
-13
lines changed

6 files changed

+51
-13
lines changed

Diff for: plugins/nf-nomad/src/main/nextflow/nomad/builders/JobBuilder.groovy

+18-8
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,22 @@ class JobBuilder {
7373
return this
7474
}
7575

76-
static Job assignDatacenters(TaskRun task, Job job){
76+
JobBuilder withDatacenters(TaskRun task){
7777
def datacenters = task.processor?.config?.get(TaskDirectives.DATACENTERS)
7878
if( datacenters ){
7979
if( datacenters instanceof List<String>) {
8080
job.datacenters( datacenters as List<String>)
81-
return job;
81+
return this;
8282
}
8383
if( datacenters instanceof Closure) {
8484
String str = datacenters.call().toString()
8585
job.datacenters( [str])
86-
return job;
86+
return this;
8787
}
8888
job.datacenters( [datacenters.toString()] as List<String>)
89-
return job
89+
return this
9090
}
91-
job
91+
this
9292
}
9393

9494
JobBuilder withNamespace(String namespace) {
@@ -291,7 +291,7 @@ class JobBuilder {
291291
taskDef
292292
}
293293

294-
static Job spreads(TaskRun task, Job jobDef, NomadJobOpts jobOpts){
294+
JobBuilder withSpreads(TaskRun task, NomadJobOpts jobOpts){
295295
def spreads = [] as List<Spread>
296296
if( jobOpts.spreadsSpec ){
297297
def list = SpreadsBuilder.spreadsSpecToList(jobOpts.spreadsSpec)
@@ -307,10 +307,20 @@ class JobBuilder {
307307
}
308308

309309
spreads.each{
310-
jobDef.addSpreadsItem(it)
310+
job.addSpreadsItem(it)
311311
}
312-
jobDef
312+
this
313313
}
314314

315+
JobBuilder withPriority(int priority){
316+
job.priority = priority
317+
this
318+
}
315319

320+
JobBuilder withPriority(TaskRun task){
321+
if( task.processor?.config?.containsKey(TaskDirectives.PRIORITY) ){
322+
withPriority( task.processor?.config?.get(TaskDirectives.PRIORITY) as int)
323+
}
324+
this
325+
}
316326
}

Diff for: plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy

+3-4
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,13 @@ class NomadService implements Closeable{
8080
.withId(id)
8181
.withName(task.name)
8282
.withType("batch")
83-
// .withDatacenters(task, this.config.jobOpts().datacenters)
83+
.withDatacenters(task)
8484
.withNamespace(this.config.jobOpts().namespace)
8585
.withTaskGroups([JobBuilder.createTaskGroup(task, args, env, this.config.jobOpts())])
86+
.withSpreads(task, this.config.jobOpts())
87+
.withPriority(task)
8688
.build()
8789

88-
JobBuilder.assignDatacenters(task, job)
89-
JobBuilder.spreads(task, job, this.config.jobOpts())
90-
9190
JobRegisterRequest jobRegisterRequest = new JobRegisterRequest()
9291
jobRegisterRequest.setJob(job)
9392

Diff for: plugins/nf-nomad/src/main/nextflow/nomad/executor/TaskDirectives.groovy

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ class TaskDirectives {
1010

1111
public static final String SPREAD = "spread"
1212

13+
public static final String PRIORITY = "priority"
14+
1315
public static final List<String> ALL = [
1416
DATACENTERS,
1517
CONSTRAINTS,
1618
SECRETS,
17-
SPREAD
19+
SPREAD,
20+
PRIORITY
1821
]
1922
}

Diff for: plugins/nf-nomad/src/test/nextflow/nomad/builders/JobBuilderSpec.groovy

+16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package nextflow.nomad.builders
1818

1919
import nextflow.nomad.config.NomadConfig
2020
import nextflow.nomad.config.NomadJobOpts
21+
import nextflow.processor.TaskProcessor
2122
import nextflow.processor.TaskRun
2223
import okhttp3.mockwebserver.MockWebServer
2324
import spock.lang.Specification
@@ -98,5 +99,20 @@ class JobBuilderSpec extends Specification {
9899
taskGroup.tasks[0].env == env
99100
}
100101

102+
def "test priority in task"(){
103+
given:
104+
def taskRun = Mock(TaskRun)
105+
taskRun.container >> "test-container"
106+
taskRun.workDir >> new File("/test/workdir").toPath()
107+
taskRun.getProcessor() >> Mock(TaskProcessor) {
108+
getConfig() >> [priority: 666]
109+
}
110+
111+
when:
112+
def job = new JobBuilder().withPriority(taskRun).build()
113+
114+
then:
115+
job.priority == 666
116+
}
101117

102118
}

Diff for: validation/debug-pipeline.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
./wait-nomad.sh
4+
5+
./nomad system gc
6+
7+
NXF_ASSETS=$(pwd)/nomad_temp/scratchdir/assets \
8+
NXF_CACHE_DIR=$(pwd)/nomad_temp/scratchdir/cache \
9+
nextflow -remote-debug run -w $(pwd)/nomad_temp/scratchdir/ "$@"

Diff for: validation/directives/nextflow.config

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ profiles{
2424
process {
2525
withName: sayHello {
2626
datacenters = ['test-datacenter', 'demo-datacenter']
27+
priority = 66
2728
}
2829
}
2930
}

0 commit comments

Comments
 (0)