Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions modules/nextflow/src/main/groovy/nextflow/script/ProcessDef.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ class ProcessDef extends BindableDef implements IterableDef, ChainableDef {
str.split(Const.SCOPE_SEP).last()
}

protected void initialize() {
// apply config settings to the process
final configProcessScope = (Map)session.config.process
new ProcessConfigBuilder(processConfig).applyConfig(configProcessScope, baseName, simpleName, processName)
}

@Override
ProcessDef clone() {
def result = (ProcessDef)super.clone()
Expand Down Expand Up @@ -144,9 +138,6 @@ class ProcessDef extends BindableDef implements IterableDef, ChainableDef {

@Override
Object run(Object[] args) {
// initialise process config
initialize()

// invoke process with legacy inputs/outputs
if( processConfig instanceof ProcessConfigV1 )
output = runV1(args, processConfig)
Expand Down Expand Up @@ -261,14 +252,23 @@ class ProcessDef extends BindableDef implements IterableDef, ChainableDef {
}

TaskProcessor createTaskProcessor() {
if( !processConfig )
initialize()
// apply process directives from config settings
applyConfig()

// create executor for process
final executor = session
.executorFactory
.getExecutor(processName, processConfig, taskBody, session)

// create task processor for process
return session
.newProcessFactory(owner)
.newTaskProcessor(processName, executor, processConfig, taskBody)
}

protected void applyConfig() {
final configProcessScope = (Map)session.config.process
new ProcessConfigBuilder(processConfig).applyConfig(configProcessScope, baseName, simpleName, processName)
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package nextflow.script

import nextflow.Session
import nextflow.executor.Executor
import nextflow.executor.ExecutorFactory
import nextflow.processor.TaskProcessor
import spock.lang.Specification
/**
*
Expand Down Expand Up @@ -58,15 +61,15 @@ class ProcessDefTest extends Specification {

when:
def copy = proc.clone()
copy.initialize()
copy.applyConfig()
then:
def cfg1 = copy.processConfig.createTaskConfig()
cfg1.getCpus()==2 // taken from the generic config
cfg1.getMemory().giga == 3 // taken from the `foo` config

when:
copy = proc.cloneWithName('flow1:bar')
copy.initialize()
copy.applyConfig()
then:
def cfg2 = copy.processConfig.createTaskConfig()
cfg2.getCpus()==4 // taken from the `bar` config
Expand All @@ -75,10 +78,38 @@ class ProcessDefTest extends Specification {

when:
copy = proc.cloneWithName('flow1:flow2:flow3:bar')
copy.initialize()
copy.applyConfig()
then:
def cfg3 = copy.processConfig.createTaskConfig()
cfg3.getCpus()==4 // <-- taken from `withName: foo`
cfg3.getMemory().giga == 8 // <-- taken from `withName: 'flow1:flow2:flow3:bar'`
}

def 'should apply config when creating task processor' () {
given:
def OWNER = Mock(BaseScript)
def CONFIG = new ProcessConfig(OWNER, 'foo')
CONFIG.container = 'source-container:1.0'
def BODY = new BodyDef({->}, 'echo hello')
def proc = new ProcessDef(OWNER, 'foo', CONFIG, BODY)
and:
proc.session = Mock(Session) {
config >> [
process: [
'withName:foo': [container: 'config-container:2.0']
]
]
executorFactory >> Mock(ExecutorFactory) {
getExecutor(_, _, _, _) >> Mock(Executor)
}
newProcessFactory(_) >> Mock(ProcessFactory) {
newTaskProcessor(_, _, _, _) >> Mock(TaskProcessor)
}
}

when:
proc.createTaskProcessor()
then:
proc.processConfig.container == 'config-container:2.0'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class ParamsDsl2Test extends Dsl2Spec {
def script = loadScript(SCRIPT)
and:
def process = ScriptMeta.get(script).getProcess('alpha')
process.initialize()

then:
def inputs = process.processConfig.getInputs()
Expand Down Expand Up @@ -70,7 +69,6 @@ class ParamsDsl2Test extends Dsl2Spec {
def script = loadScript(SCRIPT)
and:
def process = ScriptMeta.get(script).getProcess('beta')
process.initialize()

then:
def inputs = process.processConfig.getInputs()
Expand Down
Loading