protected long getOriginalJobExecutionId(final String jobName) { final List<JobInstance> jobInstances = jobOperator.getJobInstances(jobName, 0, 1); final JobInstance jobInstance = jobInstances.get(0); final List<JobExecution> jobExecutions = jobOperator.getJobExecutions(jobInstance); final JobExecution originalJobExecution = jobExecutions.get(jobExecutions.size() - 1); return originalJobExecution.getExecutionId(); }
@Override public boolean select( final JobExecution jobExecution, final Collection<Long> allJobExecutionIds) { if (excludeRunningJobExecutions) { final BatchStatus batchStatus = jobExecution.getBatchStatus(); if (batchStatus != BatchStatus.COMPLETED && batchStatus != BatchStatus.FAILED && batchStatus != BatchStatus.STOPPED && batchStatus != BatchStatus.ABANDONED) { return false; } } final long id = jobExecution.getExecutionId(); if (jobExecutionIds != null && !jobExecutionIds.isEmpty()) { return jobExecutionIds.contains(id); } if (numberOfRecentJobExecutionsToExclude != null) { int numOfLargerIds = 0; for (final Long jeid : allJobExecutionIds) { if (jeid > id) { numOfLargerIds++; if (numOfLargerIds >= numberOfRecentJobExecutionsToExclude) { return true; } } } if (numOfLargerIds < numberOfRecentJobExecutionsToExclude) { return false; } } if (jobExecutionIdFrom != null) { if (jobExecutionIdTo != null) { return id >= jobExecutionIdFrom && id <= jobExecutionIdTo; } else { return id >= jobExecutionIdFrom; } } else if (jobExecutionIdTo != null) { return id <= jobExecutionIdTo; } final Date endTime = jobExecution.getEndTime(); // End time may be null if there are unfinished batch jobs if (endTime != null) { if (withinPastMinutes != null) { final long diffMillis = System.currentTimeMillis() - endTime.getTime(); final long diffMinutes = TimeUnit.MILLISECONDS.toMinutes(diffMillis); return diffMinutes <= withinPastMinutes; } if (jobExecutionEndTimeFrom != null) { if (jobExecutionEndTimeTo != null) { return (endTime.after(jobExecutionEndTimeFrom) || endTime.equals(jobExecutionEndTimeFrom)) && (endTime.before(jobExecutionEndTimeTo) || endTime.equals(jobExecutionEndTimeTo)); } else { return endTime.after(jobExecutionEndTimeFrom) || endTime.equals(jobExecutionEndTimeFrom); } } else if (jobExecutionEndTimeTo != null) { return endTime.before(jobExecutionEndTimeTo) || endTime.equals(jobExecutionEndTimeTo); } } if (batchStatuses != null) { return batchStatuses.contains(jobExecution.getBatchStatus().name()); } if (exitStatuses != null) { return exitStatuses.contains(jobExecution.getExitStatus()); } if (jobExecutionsByJobNames != null) { return jobExecutionsByJobNames.contains(jobExecution.getJobName()); } return false; }