Hi there!
I am using the Jakarta Batch mass-indexing job and I’ve encountered the following problem now:
I need to use the Jakarta Job Listener, specifically the afterJob()
method as I want to be able to retrieve the time that the Hibernate Search mass indexing job has finished. I need jobExecution.getEndTime()
as I want users to press on a button that starts the mass indexing job and display the end time right next to the button as soon as the job is finished.
Normally I would have just registered the listener to the mass indexing job by adding it to Hibernate Search’s hibernate-search-mass-indexing.xml
. From what I’ve seen there is no way to register the listener otherwise and I haven’t seen anything in the APIs that would suggest a different solution to this problem.
Would you consider extending the API with regards to the hibernate-search-mass-indexing
job or is there any alternative to retrieve the jobExecution.getEndTime()
? Right now I am running the job on a different thread. Here’s the code:
final JobOperator jobOperator = BatchRuntime.getJobOperator();
final long executionId = jobOperator.start(MassIndexingJob.NAME, properties);
final JobExecution jobExecution = jobOperator.getJobExecution(executionId);
while (true) {
if (jobExecution.getBatchStatus() == BatchStatus.COMPLETED
|| jobExecution.getBatchStatus() == BatchStatus.FAILED
|| jobExecution.getBatchStatus() == BatchStatus.ABANDONED) {
return jobExecution.getEndTime();
}
else {
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
}
This is an obviously very ugly solution, so I’d be very thankful for some advice!