in src/main/java/org/apache/sling/jobs/it/services/AsyncJobConsumer.java [125:154]
public void execute(@NotNull final Job initialState, @NotNull final JobUpdateListener listener, @NotNull final JobCallback callback) {
LOGGER.info("Got request to start job {} ", initialState);
initialState.setState(Job.JobState.QUEUED);
listener.update(initialState.newJobUpdateBuilder().command(JobUpdate.JobUpdateCommand.UPDATE_JOB).put("processing", "step1").build());
// if the Job cant be queued locally, a RejectedExecutionException will be thrown, back to the scheduler and the job message will be put back into the queue to be retried some time later.
executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
initialState.setState(Job.JobState.ACTIVE);
listener.update(initialState.newJobUpdateBuilder().command(JobUpdate.JobUpdateCommand.UPDATE_JOB).put("processing", "step1").build());
// DO some work here.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
LOGGER.debug(e.getMessage(), e);
}
listener.update(initialState.newJobUpdateBuilder().command(JobUpdate.JobUpdateCommand.UPDATE_JOB).put("processing", "step2").build());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
LOGGER.debug(e.getMessage(), e);
}
initialState.setState(Job.JobState.SUCCEEDED);
listener.update(initialState.newJobUpdateBuilder().command(JobUpdate.JobUpdateCommand.UPDATE_JOB).put("processing", "step3").build());
callback.callback(initialState);
return null;
}
});
}