Cron event handler - synchronous or asynchronous

Hello - I have created an event handler for a scheduled event. The handler will perform a long-running operation. Looking through the Nuxeo code, I see various classes implementing AbstractWork for background processing. My question is: should I consider using the AbstractWork code? Or – will the event already be running on it's own thread by virtue of the fact that it was invoked according to a schedule?

0 votes

1 answers

63 views

ANSWER

Awesome. Thanks.
03/15/2017



A scheduled event should be managed by an asynchronous listener.

If you use a synchronous listener, it will execute in the thread of the Quartz process dealing with the scheduling of that event, and such threads are on purpose kept in very small numbers (to avoid consuming unneeded resources — there's actually just one thread in the default platform, see templates/common/config/quartz.properties). If you write such a synchronous listener for a scheduled event then it should execute very quickly, but if it needs to it can also do asynchronous Work by passing a subclass of AbstractWork to the WorkManager method schedule.

But directly writing an asynchronous listener (which is implemented using a subclass of AbstractWork itself) is simpler.

0 votes



Actually - I have a follow-up question: How does one write a Unit Test for a cron event handler? I could not find an example in the code to clone. Though - I am brand new to the platform so - may be missing the forest for the trees…
03/15/2017

org.nuxeo.ecm.core.scheduler.TestSchedulerService.testScheduleRegistration is one such test.
03/15/2017

Thanks again. The code contains the following reference: deployContrib("org.nuxeo.ecm.core.event.test", "OSGI-INF/test-scheduler-config.xml"); but I cannot find this XML in the repository. Help is appreciated.
03/15/2017

This file is nuxeo-core/nuxeo-core-event/src/test/resources/OSGI-INF/test-scheduler-config.xml
03/15/2017

Thanks.
03/15/2017