tnichol
tnichol

Reputation: 155

Batch Jobs with Grails

I work with a company that is beginning to use Grails 1.3.7 (yes, outdated, as this is the only version the vendor supports) and Groovy. We want to base our system on grails to run batch database jobs and eventually implement a web interface. What is the idiomatic way to write batch database jobs into grails and have it run on a regular schedule? Preferably without plugins, is there a way?

Alternatively, should we only use groovy scripts to run the batch jobs and put them into an old fashioned cron job, and if so, how can we extract the database connection from the WAR file or tomcat server (via JNDI)? I made some simple groovy scripts that connected to our Oracle db with hard-coded database information but probably don't want to do it that way going forward.

Perhaps there is a good beginners book that I can get to familiarize myself with grails as well?

Thanks,

Tom

Upvotes: 1

Views: 1476

Answers (3)

Hans Westerbeek
Hans Westerbeek

Reputation: 5805

The quartz plugin is the way to go. However, if you must insist on not using the plugin, you can still add the quartz jars themselves on the project's classpath (by editing BuildConfig.groovy) and by using Spring's support for talking to Quartz.

In turn, you can let Grails communicate with Spring, as described in the Grails manual. That also works in Grails 1.3.x

Upvotes: 1

JavaDev
JavaDev

Reputation: 442

It is difficult because you don't want to use plugin, as quartz is very easy to use and will suit your need.

You can try this hack as an alternative. Create a service that contains the logic of your batch job, and then create a controller action that invoke that service.

Then create a cron job from your operating system, invoking that controller action. Perhaps using wget or something custom written. This is only a hack I could think of, and not good and secure.

Upvotes: 0

dbrin
dbrin

Reputation: 15673

Your statements about not supporting grails 2x and not wanting to use plugins are alarming and raising red flags. If you can't use a particular framework as it was designed to to be used perhaps there are other alternatives that are better for you ... Having said that, I would encourage you to use the latest version of Grails as it brings benefits as well as better support going forward.

As far as running database batch jobs .. perhaps the best thing to do is just run them from a database. Oracle DB has a great jobs scheduler that works great.

If you do need to run the server side code on schedule then I would recommend Quartz plugin. It is very easy to setup and use, and comes with fairly good documentation.

Upvotes: 2

Related Questions