in src/main/java/org/apache/sling/event/impl/jobs/tasks/HistoryCleanUpTask.java [75:118]
public JobExecutionResult process(final Job job, final JobExecutionContext context) {
int age = job.getProperty(PROPERTY_AGE, DEFAULT_AGE);
if ( age < 1 ) {
age = DEFAULT_AGE;
}
final Calendar removeDate = Calendar.getInstance();
removeDate.add(Calendar.MINUTE, -age);
final String[] topics = job.getProperty(PROPERTY_TOPIC, String[].class);
final String[] states = job.getProperty(PROPERTY_STATE, String[].class);
final String logTopics = (topics == null ? "ALL" : Arrays.toString(topics));
final String logStates = (states == null ? "ALL" : Arrays.toString(states));
context.log("Cleaning up job history. Removing all jobs older than {0}, with topics {1} and states {2}",
removeDate, logTopics, logStates);
final List<String> stateList;
if ( states != null ) {
stateList = new ArrayList<>();
for(final String s : states) {
stateList.add(s);
}
} else {
stateList = null;
}
final ResourceResolver resolver = this.configuration.createResourceResolver();
try {
if ( stateList == null || stateList.contains(Job.JobState.SUCCEEDED.name()) ) {
this.cleanup(removeDate, resolver, context, configuration.getStoredSuccessfulJobsPath(), topics, null);
}
if ( stateList == null || stateList.contains(Job.JobState.DROPPED.name())
|| stateList.contains(Job.JobState.ERROR.name())
|| stateList.contains(Job.JobState.GIVEN_UP.name())
|| stateList.contains(Job.JobState.STOPPED.name())) {
this.cleanup(removeDate, resolver, context, configuration.getStoredCancelledJobsPath(), topics, stateList);
}
} catch (final PersistenceException pe) {
// in the case of an error, we just log this as a warning
this.logger.warn("Exception during job resource tree cleanup.", pe);
} finally {
resolver.close();
}
return context.result().succeeded();
}