Home How can I prevent the Quartz plugin for Grails 3 from deleting job data?
Reply: 0

How can I prevent the Quartz plugin for Grails 3 from deleting job data?

user4195 Published in March 20, 2018, 3:25 pm

I have an existing Grails 2.4.4 application which uses the Quartz plugin (version 1.0.1) to schedule jobs. In this application, I set up a bean in resources.groovy like so

quartzScheduler(SchedulerFactoryBean) {
    autoStartup = false
    schedulerName = 'reporting_quartz'
    dataSource = ref('dataSource_qrtz')
    transactionManager = ref('transactionManager')
    jobFactory = ref('quartzJobFactory')

The application uses this bean to schedule jobs to run in the future. These jobs are supposed to be picked up by another application that also uses Quartz with the same scheduler (reporting_quartz). So, I have set autoStartup = false in QuartzConfig.groovy in the application with the quartzScheduler bean so that this particular application does not run the job. Only the second application will run it at the time scheduled by the first application.

This has worked well for our Grails 2 version of the app, but now we have upgraded the first app to Grails 3.2.4 with the version of Quartz plugin 2.0.12. The issue is that the new QuartzGrailsPlugin refreshes the jobs (by calling QuartzGrailsPlugin.refreshJobs) upon app start up, which deletes a lot of other job data from the quartz database. The data is still needed by our second application to kick off other jobs that are not in the first application.

To fix, I have tried to set up Quartz clustering config in application.yml in the first app (Grails 3.2.4 version) with no luck. Here is the configuration I used:

    autoStartup: false
    jdbcStore: true
        instanceName: reporting_quartz
        instanceId: AUTO
        skipUpdateCheck: true
        class: org.quartz.simpl.SimpleThreadPool
        threadCount: 5
        threadPriority: 5
        misfireThreshold: 60000
        class: org.quartz.impl.jdbcjobstore.JobStoreTX
        driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
        useProperties: false
        tablePrefix: QRTZ_
        isClustered: true
        clusterCheckinInterval: 1000
            class: org.quartz.plugins.management.ShutdownHookPlugin
            cleanShutdown: true
        class: org.quartz.plugins.history.LoggingTriggerHistoryPlugin
        class: org.quartz.plugins.history.LoggingJobHistoryPlugin

I also tried setting these properties up in a Properties object and assigning that object to quartzProperties in the bean configuration, but I haven't had any luck preventing the application from deleting the data. The only thing that seems to work is to change the schedulerName on the bean, but then the second app will not hit the jobs scheduled by the first app.

Does anyone have any insight into this? Anyone get this scenario working successfully in their Grails 3 app? Thank you.

Edit: I am using a MySQL database for Quartz. We have multiple datasources (all MySQL databases), and the one we use for Quartz is called qrtz. Here is the config that we have in application.groovy:

    def props = {
        validationQuery = "SELECT 1"
        validationQueryTimeout = 3
        validationInterval = 15000
        testOnBorrow = true
        testWhileIdle = true
        testOnReturn = false

    dataSources {
        dataSource {
            url = "jdbc:mysql://my.url.com:3306/prod?zeroDateTimeBehavior=convertToNull"
            username = "username"
            password = "password"
            driverClassName = "com.mysql.cj.jdbc.Driver"
            dialect = org.hibernate.dialect.MySQL5InnoDBDialect

            properties props
        qrtz {
            url = "jdbc:mysql://my.url.com:3306/qrtz?zeroDateTimeBehavior=convertToNull"
            username = "username"
            password = "password"
            driverClassName = "com.mysql.cj.jdbc.Driver"
            dialect = org.hibernate.dialect.MySQL5InnoDBDialect

            properties props
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.417128 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO