Skip to content

Commit d9e55e5

Browse files
committed
Set local task exit status when time limit is exceeded
Signed-off-by: Ben Sherman <[email protected]>
1 parent 9930e35 commit d9e55e5

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

modules/nextflow/src/main/groovy/nextflow/executor/local/LocalTaskHandler.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class LocalTaskHandler extends TaskHandler implements FusionAwareTask {
218218
*/
219219
if( elapsedTimeMillis() > wallTimeMillis ) {
220220
destroy()
221+
task.exitStatus = process.exitValue()
221222
task.stdout = outputFile
222223
task.stderr = errorFile
223224
task.error = new ProcessException("Process exceeded running time limit (${task.config.getTime()})")

modules/nextflow/src/test/groovy/nextflow/executor/local/LocalTaskHandlerTest.groovy

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ import java.nio.file.Path
2121

2222
import nextflow.Global
2323
import nextflow.container.DockerConfig
24+
import nextflow.exception.ProcessException
2425
import nextflow.file.http.XPath
2526
import nextflow.processor.TaskBean
2627
import nextflow.processor.TaskConfig
2728
import nextflow.processor.TaskRun
29+
import nextflow.processor.TaskStatus
30+
import nextflow.util.Duration
2831
import spock.lang.Specification
2932
/**
3033
*
@@ -83,4 +86,33 @@ class LocalTaskHandlerTest extends Specification {
8386
cleanup:
8487
builder?.redirectOutput()?.file()?.delete()
8588
}
89+
90+
def 'should kill task when task exceeds time limit' () {
91+
given:
92+
def workDir = Path.of('/tmp/test-work-dir')
93+
def task = Mock(TaskRun) {
94+
getWorkDir() >> workDir
95+
getConfig() >> Mock(TaskConfig) {
96+
getTime() >> Duration.of(100)
97+
}
98+
}
99+
and:
100+
def handler = Spy(new LocalTaskHandler(task, Mock(LocalExecutor))) {
101+
buildTaskWrapper() >> {}
102+
elapsedTimeMillis() >> 200
103+
}
104+
handler.@process = Mock(Process) {
105+
exitValue() >> 143 // Typical exit code for SIGTERM
106+
}
107+
handler.status = TaskStatus.RUNNING
108+
109+
when:
110+
def completed = handler.checkIfCompleted()
111+
112+
then:
113+
completed == true
114+
1 * task.setExitStatus(143)
115+
1 * task.setError(_ as ProcessException)
116+
handler.status == TaskStatus.COMPLETED
117+
}
86118
}

0 commit comments

Comments
 (0)