Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to build a queue for long-running jobs in a Grails app?

I have a Grails app that has some computationally intensive optimizations with a running time of ~5 minutes (perhaps more). Currently, I'm doing these in the main request thread, i.e. it takes 5 minutes for the request to return. It works, but is of course horrible from a usability perspective.

So what's the best way to implement this in an asynchronous way? I assume a ThreadPoolExecutor would have to be involved, but how do I start and access it? Can I model it as a Grails Service? Or a Job (seems that those are only meant for recurring jobs though)?

Also, what's the best way to handle job status? Via a a flag or perhaps an entire new class in the DB? Have the browser show a spinner and keep polling until the status changes?

like image 777
Michael Borgwardt Avatar asked Jul 26 '09 11:07

Michael Borgwardt


3 Answers

There is a grails plugin background-thread which might be just what you are looking for.

Of course it would be possible to roll your own thread pooling or use existing Java stuff.

like image 134
Sean A.O. Harney Avatar answered Nov 01 '22 06:11

Sean A.O. Harney


I'd use the grails JMS Plugin for this.

Then you can create a service with an "onMessage" method that interacts automatically with an underlying jms provider (like OpenMQ or ActiveMQ.

It makes this kind of thing pretty easy.

like image 3
Ted Naleid Avatar answered Nov 01 '22 06:11

Ted Naleid


Background-thread plugin is outdated so I wouldn't recommend using it and also the JMS seems overkill for background processing. JMS is more of a message queue rather than background processing utility.

I would recommend either using Quartz plugin or using the gpars.

like image 3
Ganesh Krishnan Avatar answered Nov 01 '22 08:11

Ganesh Krishnan