Our application is deployed to 2 web servers for load balancing and redundancy. We have a couple of Quartz jobs that run once every day. The job only needs to execute on one of the web servers, not both. Eventually, we will probably move these jobs to a job server but for now, is there a way via config or environment variable or something that I can do so that the jobs only run on one of my servers?
In QuartzConfig.groovy
you can enable or disable the Quartz plugin for specific environments.
environments {
runQuartz {
autoStartup = true
}
dontRunQuartz {
autoStartup = false
}
}
so one way would be to use -Dgrails.env=runQuartz
and -Dgrails.env=dontRunQuartz
in your Tomcat startup parameters.
A terrible hack would be to have your Quartz Job attempt to lock a shared database table - the job that gets the lock can run, otherwise, abort.
I think a third option would be to use a JDBC job store, although I have no experience with using that. Briefly mentioned in the Quartz plugin docs.