in src/main/java/org/apache/sling/event/impl/jobs/JobHandler.java [116:159]
public void finished(final Job.JobState state, final boolean keepJobInHistory, final Long duration) {
final boolean isSuccess = (state == Job.JobState.SUCCEEDED);
withJobResource((jobResource,mvm) -> {
try {
ResourceResolver rr = jobResource.getResourceResolver();
String newPath = null;
if (keepJobInHistory) {
newPath = this.configuration.getStoragePath(job.getTopic(), job.getId(), isSuccess);
final Map<String, Object> props = new HashMap<>(mvm);
props.put(JobImpl.PROPERTY_FINISHED_STATE, state.name());
if (isSuccess) {
// we set the finish date to start date + duration
final Date finishDate = new Date();
finishDate.setTime(job.getProcessingStarted().getTime().getTime() + duration);
final Calendar finishCal = Calendar.getInstance();
finishCal.setTime(finishDate);
props.put(JobImpl.PROPERTY_FINISHED_DATE, finishCal);
} else {
// current time is good enough
props.put(JobImpl.PROPERTY_FINISHED_DATE, Calendar.getInstance());
}
if (job.getProperty(Job.PROPERTY_RESULT_MESSAGE) != null) {
props.put(Job.PROPERTY_RESULT_MESSAGE, job.getProperty(Job.PROPERTY_RESULT_MESSAGE));
}
ResourceHelper.getOrCreateResource(rr, newPath, props);
}
rr.delete(jobResource);
rr.commit();
if (keepJobInHistory && configuration.getMainLogger().isDebugEnabled()) {
if (isSuccess) {
configuration.getMainLogger().debug("Kept successful job {} at {}", Utility.toString(job),
newPath);
} else {
configuration.getMainLogger().debug("Moved cancelled job {} to {}", Utility.toString(job),
newPath);
}
}
} catch (final PersistenceException pe) {
this.configuration.getMainLogger().warn("Unable to finish job " + job.getId(), pe);
}
return false; // this return value is ignored
});
}