Using grails data sources in a quartz plugin

I want to create quartz jobs that use JdbcStore, as described in the docs clustering section, in Burt's example.

This example shows how to configure quartz using the quartz.properties file.

Now I would like my jdbc repository to be the same database as my grails application, so I have less duplication settings.

So, if I manually create the necessary tables in my database, can I use the default dataSource configured in Datasource.groovy with the quartz plugin?

I am using grails 2.4.4 and quartz 1.0.2.

In other terms, can I add my settings to QuartzConfig.groovy and not create a new quartz.properties file? At least I could use the settings of individual environments.

Will there be something like this in action at QuartzConfig.groovy?

quartz { autoStartup = true jdbcStore = true waitForJobsToCompleteOnShutdown = true exposeSchedulerInRepository = true props { scheduler.skipUpdateCheck = true threadPool.class = 'org.quartz.simpl.SimpleThreadPool' threadPool.threadCount = 50 threadPool.threadPriority = 9 jobStore.misfireThreshold = 60000 jobStore.class = 'impl.jdbcjobstore.JobStoreTX' jobStore.driverDelegateClass = 'org.quartz.impl.jdbcjobstore.StdJDBCDelegate' jobStore.useProperties = false jobStore.tablePrefix = 'QRTZ_' jobStore.isClustered = true jobStore.clusterCheckinInterval = 5000 plugin.shutdownhook.class = 'org.quartz.plugins.management.ShutdownHookPlugin' plugin.shutdownhook.cleanShutdown = true jobStore.dataSource = 'myDS' // [...] } 
+2
grails quartz-scheduler grails-plugin
source share
1 answer

I managed to configure all my settings in QuartzConfig.groovy. The only thing I had to remove in order to get it working was the specific database settings.

In addition, I had to add the scheduler.idleWaitTime = 1000 property, as described here http://www.quartz-scheduler.org/generated/2.2.1/pdf/Quartz_Scheduler_Configuration_Guide.pdf on page 12, because, despite the fact that my work is called MyJob.triggerNow(paramsMap) , there was a delay of 20 to 30 seconds before it started.

If scheduler.idleWaitTime set to 1 second, the job actually starts 1 second after it is submitted.

QuartzProperties.groovy actually accepts all the properties described in the quartz configuration documents (for example: http://quartz-scheduler.org/documentation/quartz-2.1.x/configuration/ConfigJobStoreTX ). Just put them in the props {...} block and remove the org.quartz prefix.

Here is my final config as an example:

 quartz { autoStartup = true jdbcStore = true waitForJobsToCompleteOnShutdown = true // Allows monitoring in Java Melody (if you have the java melody plugin installed in your grails app) exposeSchedulerInRepository = true props { scheduler.skipUpdateCheck = true scheduler.instanceName = 'my_reporting_quartz' scheduler.instanceId = 'AUTO' scheduler.idleWaitTime = 1000 threadPool.'class' = 'org.quartz.simpl.SimpleThreadPool' threadPool.threadCount = 10 threadPool.threadPriority = 7 jobStore.misfireThreshold = 60000 jobStore.'class' = 'org.quartz.impl.jdbcjobstore.JobStoreTX' jobStore.driverDelegateClass = 'org.quartz.impl.jdbcjobstore.StdJDBCDelegate' jobStore.useProperties = false jobStore.tablePrefix = 'QRTZ_' jobStore.isClustered = true jobStore.clusterCheckinInterval = 5000 plugin.shutdownhook.'class' = 'org.quartz.plugins.management.ShutdownHookPlugin' plugin.shutdownhook.cleanShutdown = true } } 

Do not forget to create sql tables with the corresponding script, which is located at / path / to / your / project / target / work / plugins / quartz-1.0.2 / src / templates / sql / ...

+6
source share

All Articles