|
44 | 44 | import java.nio.file.DirectoryStream; |
45 | 45 | import java.nio.file.Files; |
46 | 46 | import java.nio.file.Path; |
| 47 | +import java.sql.SQLException; |
47 | 48 | import java.util.ArrayList; |
48 | 49 | import java.util.Arrays; |
49 | 50 | import java.util.Collections; |
@@ -81,17 +82,37 @@ public String getName() |
81 | 82 | return "DeleteSequenceAnalysisArtifacts"; |
82 | 83 | } |
83 | 84 |
|
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 |
85 | 86 | private void checkJobCancelled(Logger log) |
86 | 87 | { |
87 | 88 | // Make the assumption there is only one active maintenance job at a time: |
88 | 89 | SimpleFilter filter = new SimpleFilter(FieldKey.fromString("description"), SYSTEM_MAINTENANCE_DESCRIPTION). |
89 | 90 | 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) |
93 | 114 | { |
94 | | - log.error("Unable to find rowId for job"); |
| 115 | + log.debug("Unable to find rowId for job", new Exception()); |
95 | 116 | return; |
96 | 117 | } |
97 | 118 |
|
|
0 commit comments