Skip to content

Commit 5df0026

Browse files
committed
Bugfix to maintenance job cancellation
1 parent 3013b74 commit 5df0026

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

SequenceAnalysis/src/org/labkey/sequenceanalysis/SequenceAnalysisMaintenanceTask.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.nio.file.DirectoryStream;
4545
import java.nio.file.Files;
4646
import java.nio.file.Path;
47+
import java.sql.SQLException;
4748
import java.util.ArrayList;
4849
import java.util.Arrays;
4950
import java.util.Collections;
@@ -81,17 +82,37 @@ public String getName()
8182
return "DeleteSequenceAnalysisArtifacts";
8283
}
8384

84-
// NOTE: if there is a more direct way to locate the JobID this should be replaced
85+
// NOTE: if there is a more direct way to locate the JobID this hack should be replaced
8586
private void checkJobCancelled(Logger log)
8687
{
8788
// Make the assumption there is only one active maintenance job at a time:
8889
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("description"), SYSTEM_MAINTENANCE_DESCRIPTION).
8990
addCondition(FieldKey.fromString("container"), ContainerManager.getRoot().getId()).
90-
addInClause(FieldKey.fromString("status"), Arrays.asList(PipelineJob.TaskStatus.cancelling.name(), PipelineJob.TaskStatus.running.name()));
91-
Integer rowId = new TableSelector(DbSchema.get("pipeline", DbSchemaType.Module).getTable(JOB_TABLE), PageFlowUtil.set("RowId"), filter, null).getObject(Integer.class);
92-
if (rowId == null)
91+
addCondition(FieldKey.fromString("modified"), new Date(), CompareType.DATE_EQUAL);
92+
int rowId = new TableSelector(DbSchema.get("pipeline", DbSchemaType.Module).getTable(JOB_TABLE), PageFlowUtil.set("RowId", "Status"), filter, null).resultsStream(false).filter(rs -> {
93+
try
94+
{
95+
String val = rs.getString(FieldKey.fromString("status"));
96+
return val != null && (val.toLowerCase().startsWith(PipelineJob.TaskStatus.cancelling.name()) || val.toLowerCase().startsWith(PipelineJob.TaskStatus.running.name()));
97+
}
98+
catch (SQLException e)
99+
{
100+
throw new RuntimeException(e);
101+
}
102+
}).map(rs -> {
103+
try
104+
{
105+
return rs.getInt(FieldKey.fromString("RowId"));
106+
}
107+
catch (SQLException e)
108+
{
109+
throw new RuntimeException(e);
110+
}
111+
}).max(Integer::compareTo).orElse(-1);
112+
113+
if (rowId == -1)
93114
{
94-
log.error("Unable to find rowId for job");
115+
log.debug("Unable to find rowId for job", new Exception());
95116
return;
96117
}
97118

0 commit comments

Comments
 (0)