Question

In my Grails project i need to create a routine so that, in xx seconds, i need to query the database and send an email to the found users. This routine must be running all the time.

I want to know the best way to do this, i'm looking for the easiest way, using plugins or not. I have found similar answers to this same question, but all of them were not clear enough because my knowledge with Grails/Groovy is short.

thanks in advanced, RR

Was it helpful?

Solution

This is easily done with the Quartz plugin
To install, add

compile ':quartz:0.4.2'

to the plugins section of BuildConfig.groovy, then run grails compile, or if you're on Grails 2.0 run grails refresh-dependencies, to install the plugin.
Then you can create a new job with grails create-job my.package.My , and you will get a generated class MyJob. Inside the execute method you can write you code, or better: call a service where you place your logic. The service will be automatically injected into your job, so all you need to do is to add def myService at the top of your job class (if you service is called MyService)

And for sending mail, there's the Mail plugin

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top