Skip to content

Commit 21390a1

Browse files
Add isCompleted check in getNumSpotInterruptions (#6806) [e2e prod]
Signed-off-by: munishchouhan <hrma017@gmail.com> Co-authored-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
1 parent c65f187 commit 21390a1

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

plugins/nf-amazon/src/main/nextflow/cloud/aws/batch/AwsBatchTaskHandler.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ class AwsBatchTaskHandler extends TaskHandler implements BatchHandler<String,Job
925925
* @return The number of times this job was retried due to spot instance reclamation
926926
*/
927927
protected Integer getNumSpotInterruptions(String jobId) {
928-
if (!jobId)
928+
if (!jobId || !isCompleted())
929929
return null
930930

931931
try {

plugins/nf-amazon/src/test/nextflow/cloud/aws/batch/AwsBatchTaskHandlerTest.groovy

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ class AwsBatchTaskHandlerTest extends Specification {
908908
when:
909909
def trace = handler.getTraceRecord()
910910
then:
911-
1 * handler.isCompleted() >> false
911+
2 * handler.isCompleted() >> false
912912
1 * handler.getMachineInfo() >> new CloudMachineInfo('x1.large', 'us-east-1b', PriceModel.spot)
913913

914914
and:
@@ -1195,12 +1195,14 @@ class AwsBatchTaskHandlerTest extends Specification {
11951195
when:
11961196
def resultNoAttempts = handler.getNumSpotInterruptions('job-123')
11971197
then:
1198+
1 * handler.isCompleted() >> true
11981199
1 * handler.describeJob('job-123') >> JobDetail.builder().attempts([]).build()
11991200
resultNoAttempts == 0
12001201

12011202
when:
12021203
def resultNonSpot = handler.getNumSpotInterruptions('job-456')
12031204
then:
1205+
1 * handler.isCompleted() >> true
12041206
1 * handler.describeJob('job-456') >> JobDetail.builder().attempts([attempt1, attempt2]).build()
12051207
resultNonSpot == 0
12061208
}
@@ -1212,18 +1214,21 @@ class AwsBatchTaskHandlerTest extends Specification {
12121214
when:
12131215
def resultNotCompleted = handler.getNumSpotInterruptions('job-123')
12141216
then:
1215-
1 * handler.describeJob(_)
1217+
1 * handler.isCompleted() >> false
1218+
0 * handler.describeJob(_)
12161219
resultNotCompleted == null
12171220

12181221
when:
12191222
def resultNullJobId = handler.getNumSpotInterruptions(null)
12201223
then:
1224+
0 * handler.isCompleted()
12211225
0 * handler.describeJob(_)
12221226
resultNullJobId == null
12231227

12241228
when:
12251229
def resultException = handler.getNumSpotInterruptions('job-789')
12261230
then:
1231+
1 * handler.isCompleted() >> true
12271232
1 * handler.describeJob('job-789') >> { throw new RuntimeException("Error") }
12281233
resultException == null
12291234
}

plugins/nf-google/src/main/nextflow/cloud/google/batch/GoogleBatchTaskHandler.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ class GoogleBatchTaskHandler extends TaskHandler implements FusionAwareTask {
655655
*/
656656

657657
protected Integer getNumSpotInterruptions(String jobId) {
658-
if (!jobId || !taskId) {
658+
if (!jobId || !taskId || !isCompleted()) {
659659
return null
660660
}
661661

plugins/nf-google/src/test/nextflow/cloud/google/batch/GoogleBatchTaskHandlerTest.groovy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ class GoogleBatchTaskHandlerTest extends Specification {
419419
when:
420420
def trace = handler.getTraceRecord()
421421
then:
422-
1 * handler.isCompleted() >> true
422+
2 * handler.isCompleted() >> true
423423
1 * client.getTaskStatus('xyz-123', '0') >> taskStatus
424424
and:
425425
trace.native_id == 'xyz-123/0/789'
@@ -869,6 +869,7 @@ class GoogleBatchTaskHandlerTest extends Specification {
869869
def result = handler.getNumSpotInterruptions('job-123')
870870

871871
then:
872+
handler.isCompleted() >> true
872873
result == 0
873874
}
874875

@@ -900,6 +901,7 @@ class GoogleBatchTaskHandlerTest extends Specification {
900901
def result = handler.getNumSpotInterruptions('job-123')
901902

902903
then:
904+
handler.isCompleted() >> true
903905
result == 2
904906
}
905907

@@ -913,6 +915,7 @@ class GoogleBatchTaskHandlerTest extends Specification {
913915
def resultIncompleteTask = handler.getNumSpotInterruptions('job-123')
914916

915917
then:
918+
handler.isCompleted() >> false
916919
resultNullJobId == null
917920
resultIncompleteTask == null
918921
}
@@ -929,6 +932,7 @@ class GoogleBatchTaskHandlerTest extends Specification {
929932
def result = handler.getNumSpotInterruptions('job-123')
930933

931934
then:
935+
handler.isCompleted() >> true
932936
result == null
933937
}
934938

0 commit comments

Comments
 (0)