Jakarta Batch JobListener for MassIndexingJob

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-indexingjob 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!

Hey,

Thanks for reaching out. Hmm, what you have in your example is more or less what we are currently doing in our tests :smiley:.
I can’t think of something that you could leverage right now to get the behaviour you want out of the mass indexing job.

If you go with the massindexer instead: Hibernate Search 7.2.2.Final: Reference Documentation then you could implement your custom MassIndexingMonitor where you’d be able to add some logic when the indexing starts and completes.

Sure, if you are interested, you could open a Jira ticket (Hibernate Search - Issues - Hibernate JIRA) to discuss the API and if you’d then want to provide a patch with the implementation, that is also welcome :smiley:.

1 Like

Thank you for the reply!

Yes, for some reason I decided to go for the Jakarta mass Indexer a while ago. But as it turns out, the massindexer supports everything I currently need, so thank you for the reminder :blush:.

I’ll look into it, thank you. :slight_smile:
Have a nice day!

1 Like