grails / grails-quartz

This project provides integration of the Quartz scheduling framework into the Grails Framework
http://grails.org/plugin/quartz
Apache License 2.0
76 stars 90 forks source link

Plugin deletes the the quartz data from database #96

Open nmajeski opened 6 years ago

nmajeski commented 6 years ago

Hi, I have an issue when using this plugin.

I am trying to use a SchedulerFactoryBean that I configure in resources.groovy in one of my Grails applications to schedule times for some jobs to be triggered. I schedule these jobs in my application that has the quartz autoStartup set to false. This application uses our MySQL database that we designated for Quartz data.

A second application contains the same jobs plus others, but it has the quartz autoStartup config set to true. It is also configured to track the triggers and job data using the same MySQL database and scheduler as the first app. So, the first app is supposed to set up the trigger and schedule, and the second app is supposed to kick off the job at the scheduled time.

Here is the bean configuration in the first application:

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

This has worked for me in Grails 2.4.4. However, since I migrated over to Grails 3.2.4 and started using a newer version of this plugin (2.0.12), I see that upon startup of the first app, the plugin's code QuartzGrailsPlugin.refreshJobs gets called and deletes all of the data in my table QRTZ_JOB_DETAILS as well as some of the trigger tables (i.e. QRTZ_TRIGGERS). This stops the second app's jobs (in particular those jobs that are not in the first app and are in the second app), and I lose all of the triggers that have been scheduled.

I tried to set up a Quartz clustering configuration in my application.yml file in the first app, but that does not stop the plugin from deleting the data in my tables.

I also tried to do this by putting the necessary properties into a properties file and then specifying configLocation in the quartzScheduler bean config. It doesn't seem to stop the plugin from removing my job/trigger data either.

I also tried to simply set pluginEnabled = false in the application.yml of the first app. It doesn't delete any data, but it causes my application to crash with the following error:

java.lang.NullPointerException: Cannot get property 'group' on null object
        at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:60)
        at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:172)
        at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:47)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296)
        at grails.plugins.quartz.QuartzJob$Trait$Helper.schedule(QuartzJob.groovy:58)
        at grails.plugins.quartz.QuartzJob$Trait$Helper$schedule$0.call(Unknown Source)

I also tried to schedule the jobs in another way, by removing the bean and using the schedule method of QuartzJob, which is available on the jobs that I want to schedule. Here is the config for that in application.yml:

quartz:
    autoStartup: false
    jdbcStore: true
    waitForJobsToCompleteOnShutdown: true

    scheduler:
        instanceName: 'reporting_quartz'
        instanceId: 'AUTO'
        skipUpdateCheck: true

    threadPool:
        class: 'org.quartz.simpl.SimpleThreadPool'
        threadCount: 5
        threadPriority: 5

    jobStore:
        class: 'org.quartz.impl.jdbcjobstore.JobStoreTX'
        misfireThreshold: 60000
        driverDelegateClass: 'org.quartz.impl.jdbcjobstore.StdJDBCDelegate'
        useProperties: false
        tablePrefix: 'QRTZ_'
        isClustered: true
        clusterCheckinInterval: 5000
        dataSource: 'development'

    plugin:
        shutdownhook.cleanShutdown: true
        shutdownhook.class: 'org.quartz.plugins.management.ShutdownHookPlugin'

    triggerHistory.class: 'org.quartz.plugins.history.LoggingTriggerHistoryPlugin'
    jobHistory.class: 'org.quartz.plugins.history.LoggingJobHistoryPlugin'

    dataSource:
        development:
            driver: 'com.mysql.jdbc.Driver'
            URL: 'jdbc:mysql://my.qa.db.url.com:3306/qrtz?zeroDateTimeBehavior=convertToNull'
            user: 'user'
            password: 'pass'
            maxConnections: 28
            validationQuery: 'select 1'

Unfortunately, it uses my main data source instead of using the qrtz database that I specify in my dataSource block.

Is this an issue or is there some workaround for this that I am not seeing? Please let me know. Thank you!

Edit: I downgraded to version 2.0.11, and the issue no longer occurs with my original configuration, probably because there is no more QuartzGrailsPlugin.refreshJobs method in this version.

ravikovour commented 5 years ago

This is a critical issue as the jobs created using native quartz api also getting deleted from quartz jobs database.

roeiba commented 3 years ago

+1

dylankolson commented 3 years ago

+1 seeing this issue using 2.0.13

justCodeItVishnu commented 1 year ago

+1