Hi all,

I'm hooking up a data import batch job with Quartz to Wicket and have
struck an issue - how do you notify a Wicket page that the batch job is
complete?

I originally planned to update the Wicket session with the running count of
how many items are processed. However, the Wicket request cycle expires so
it is not possible to update the session after the page is rendered.


To create the job:

JobDataMap dataMap = new JobDataMap();
> dataMap.put("service", getService());
> dataMap.put("deck", deck);
> dataMap.put("importType", importType);
> dataMap.put("fieldMapping", fieldMapping);
> dataMap.put("fileUploaded", fileUploaded);
> dataMap.put("totalRecords", prevImportSummary.totalRecordsInImport);
> dataMap.put("callback", this);
> // Create a new job with a basic trigger
> JobDetail job = newJob(DataImportJob.class
> ).usingJobData(dataMap).build();
> Trigger trigger =
> newTrigger().startNow().withSchedule(simpleSchedule()).build();
> try {
> // Schedule the job for immediate start
> TorScheduler.getScheduler().scheduleJob(job, trigger);
> } catch (SchedulerException se) {
> TorScheduler.getLogger().error(se.getMessage());
> throw new TorException("Cannot start the data import job");
> }

     The data import job uses a callback to the Wicket page:

callback.updateTotal(totalRecords);
>
    callback.updateProgress(/* 0 */ totalRecords, false); // TODO:
> Temporarily skip the progress bar page
>

>
    // Now add the entries to the repository
>
    ImportSummary importSummary = dataImportProcess.commit(callback);
>
    callback.updateImportSummary(importSummary);
>

The callback has this implementation (in the page):

 public void updateProgress(int count, boolean error) {
>
>   // Attempt to reuse the same session as before (left open)
>
>  session.setAttribute("importItemsDone", (Integer) count);
>
>  session.setAttribute("importIsInError", (Boolean) error);
>
> }
>
>  @Override
>
> public void updateTotal(int total) {
>
>
>  // Attempt to reuse the same session as before (left open)
>
>  session.setAttribute("importItemsTotal", (Integer) total);
>
> }
>
>
>  @Override
>
> public void updateImportSummary(ImportSummary importSummary) {
>
>
>  // Attempt to reuse the same session as before (left open)
>
>  session.setAttribute("importSummary", importSummary);
>
> }
>

However, I get this exception when attempting to update the Wicket session
with the progress counter:

java.lang.IllegalStateException: Cannot set the attribute: no RequestCycle
available.  If you get this error when using WicketTester.startPage(Page),
make sure to call WicketTester.createRequestCycle() beforehand.
at org.apache.wicket.Session.setAttribute(Session.java:773)
at
com.xxx.tor.webapp.profile.Wiz13ImportResults.updateTotal(Wiz13ImportResults.java:208)
at com.xxx.tor.webapp.batch.DataImportJob.importNow(DataImportJob.java:53)
at com.xxx.tor.webapp.batch.DataImportJob.execute(DataImportJob.java:83)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)


Is this the best approach? Or should I attempt to use methods on the Quartz
scheduler to get the current progress of the batch job from within
AbstractAjaxTimerBehavior.onTimer( )?

I am using the JQWicket (jQuery UI) progress bar... with a 5 second delay
on updates to the page.

Cheers,

Nigel


-- 
e: ni...@joinsomeone.com
m: +61 403 930 963

Get together for fun activities at www.joinsomeone.com

Like us on Facebook www.facebook.com/JoinSomeone
Follow us on Twitter @JoinSomeone

Reply via email to