Using grails datasources in quartz plugin

孤街醉人 提交于 2019-12-05 05:02:38

问题


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

The example shows how to configure quartz using a quartz.properties file.

Now, I'd like my jdbc store to be the same database as my grails application, so that I have less settings to duplicate.

So, assuming I manually create the required tables in my database, is it possible to use the default dataSource configured in Datasource.groovy with the quartz plugin ?

I'm using grails 2.4.4 and quartz 1.0.2.

In other terms, can I add my settings to QuartzConfig.groovy rather than creating a new quartz.properties file ? At least I could benefit from the separate environments settings.

Would something like this be valid in 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'
    // [...]
}

回答1:


I managed to tweak all my settings in QuartzConfig.groovy. The only thing I had to remove to make it work were the database specific options.

Also, I had to add the property scheduler.idleWaitTime = 1000 as advised here http://www.quartz-scheduler.org/generated/2.2.1/pdf/Quartz_Scheduler_Configuration_Guide.pdf on page 12, because despite my job being called as MyJob.triggerNow(paramsMap), there was a 20 to 30 seconds delay before it actually started.

With scheduler.idleWaitTime set to 1 second, the job indeed triggers 1 second after it has been submitted.

QuartzProperties.groovy actually accepts all the properties described in the quartz configuration docs (e.g. : http://quartz-scheduler.org/documentation/quartz-2.1.x/configuration/ConfigJobStoreTX). Just put them inside 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

    }
}

Don't forget to create the sql tables with the appropriate script, which is located at /path/to/your/project/target/work/plugins/quartz-1.0.2/src/templates/sql/...



来源:https://stackoverflow.com/questions/28246086/using-grails-datasources-in-quartz-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!