|
26 | 26 | import java.util.Set; |
27 | 27 | import java.util.concurrent.locks.Lock; |
28 | 28 | import java.util.concurrent.locks.ReentrantLock; |
| 29 | +import java.util.stream.Collectors; |
29 | 30 |
|
30 | 31 | import org.apache.commons.logging.Log; |
31 | 32 | import org.apache.commons.logging.LogFactory; |
@@ -106,7 +107,7 @@ SELECT COUNT(*) |
106 | 107 | private static final String GET_RUNNING_EXECUTION_FOR_INSTANCE = """ |
107 | 108 | SELECT E.JOB_EXECUTION_ID |
108 | 109 | FROM %PREFIX%JOB_EXECUTION E, %PREFIX%JOB_INSTANCE I |
109 | | - WHERE E.JOB_INSTANCE_ID=I.JOB_INSTANCE_ID AND I.JOB_INSTANCE_ID=? AND E.STATUS IN ('STARTING', 'STARTED', 'STOPPING') |
| 110 | + WHERE E.JOB_INSTANCE_ID=I.JOB_INSTANCE_ID AND I.JOB_NAME=? AND E.STATUS IN ('STARTING', 'STARTED', 'STOPPING') |
110 | 111 | """; |
111 | 112 |
|
112 | 113 | private static final String CURRENT_VERSION_JOB_EXECUTION = """ |
@@ -340,21 +341,10 @@ private long getJobInstanceId(long jobExecutionId) { |
340 | 341 |
|
341 | 342 | @Override |
342 | 343 | public Set<JobExecution> findRunningJobExecutions(String jobName) { |
343 | | - final Set<JobExecution> result = new HashSet<>(); |
344 | | - List<Long> jobInstanceIds = this.jobInstanceDao.getJobInstanceIds(jobName); |
345 | | - for (long jobInstanceId : jobInstanceIds) { |
346 | | - List<Long> runningJobExecutionIds = getJdbcTemplate() |
347 | | - .queryForList(getQuery(GET_RUNNING_EXECUTION_FOR_INSTANCE), Long.class, jobInstanceId); |
348 | | - if (runningJobExecutionIds.isEmpty()) { |
349 | | - continue; |
350 | | - } |
351 | | - // There should be only one running execution per job instance, enforced at |
352 | | - // startup time |
353 | | - Long jobExecutionId = runningJobExecutionIds.get(0); |
354 | | - JobExecution runningJobExecution = getJobExecution(jobExecutionId); |
355 | | - result.add(runningJobExecution); |
356 | | - } |
357 | | - return result; |
| 344 | + return getJdbcTemplate().queryForList(getQuery(GET_RUNNING_EXECUTION_FOR_INSTANCE), Long.class, jobName) |
| 345 | + .stream() |
| 346 | + .map(this::getJobExecution) |
| 347 | + .collect(Collectors.toSet()); |
358 | 348 | } |
359 | 349 |
|
360 | 350 | @Override |
|
0 commit comments