To group the Quartz plugin in Grails, you need to add some files to your project. First install grails-app/conf/QuartzConfig.groovy and make sure jdbcStore enabled.
quartz { autoStartup = true jdbcStore = true waitForJobsToCompleteOnShutdown = true }
Then install the Hibernate configuration files related to the database to which you will connect. For example, with Oracle, the basic xibernate xml configuration in grails-app/conf/hibernate/hibernate.cfg.xml :
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC '-//Hibernate/Hibernate Configuration DTD 3.0//EN' 'http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd'> <hibernate-configuration> <session-factory> <mapping resource="Quartz.oracle.hbm.xml"/> </session-factory> </hibernate-configuration>
The actual Quartz-Hibernate SQL file for this example will be called Quartz.oracle.hbm.xml and will be in the same directory. These files should be available in the Quartz plugin on GitHub ( https://github.com/nebolsin/grails-quartz ) under src/templates/sql . Please note that these scripts only work for the DataSource create and create-drop , so you need to manually create the Quartz tables for update if they do not already exist from the previous run.
Create the grails-app/conf/quartz/quartz.properties and modify it to suit your business needs:
org.quartz.scheduler.instanceId = AUTO org.quartz.scheduler.skipUpdateCheck = true org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool org.quartz.threadPool.threadCount = 4 org.quartz.threadPool.threadPriority = 1 org.quartz.jobStore.misfireThreshold = 60000 org.quartz.jobStore.maxMisfiresToHandleAtATime = 2 org.quartz.jobStore.clusterCheckinInterval = 5000 org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.oracle.OracleDelegate org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX org.quartz.jobStore.tablePrefix = QRTZ_ org.quartz.jobStore.isClustered = true org.quartz.jobStore.useProperties = false org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin org.quartz.plugin.shutdownhook.cleanShutdown = true org.quartz.plugin.triggerHistory.class = org.quartz.plugins.history.LoggingTriggerHistoryPlugin org.quartz.plugin.jobHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin
Pay attention to the above properties, you can set org.quartz.plugins in the Log4j Config.groovy to register the corresponding task and trigger trigger information. I think the info level should be sufficient.
Edit or create scripts/_Events.groovy and add the following closure to the war modification. This fixes the known Quartz plugin error to set the correct quartz.properties , and not empty from the plugin, to the final war file.
eventCreateWarStart = { warName, stagingDir -> // Make sure we have the correct quartz.properties in the // correct place in the war to enable clustering ant.delete(dir:"${stagingDir}/WEB-INF/classes/quartz") ant.copy(file:"${basedir}/grails-app/conf/quartz/quartz.properties", todir:"${stagingDir}/WEB-INF/classes") }
And you need to do ...
PS If you are using an Oracle database, add the following to BuildConfig.groovy in the dependency block so that you have access to the Quartz-Oracle communication drivers:
runtime("org.quartz-scheduler:quartz-oracle:1.7.2") { // Exclude quartz as 1.7.3 is included from the plugin excludes('quartz') }
PPS sql files from the link above is just SQL. To connect to the hibernation file, simply merge each individual SQL command using the Hibernate database-object node, like this (again w / Oracle example):
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-mapping PUBLIC '-//Hibernate/Hibernate Mapping DTD 3.0//EN' 'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'> <hibernate-mapping> <database-object> <create> CREATE TABLE QRTZ_JOB_DETAILS ( JOB_NAME VARCHAR2(200) NOT NULL, JOB_GROUP VARCHAR2(200) NOT NULL, DESCRIPTION VARCHAR2(250) NULL, JOB_CLASS_NAME VARCHAR2(250) NOT NULL, IS_DURABLE VARCHAR2(1) NOT NULL, IS_VOLATILE VARCHAR2(1) NOT NULL, IS_STATEFUL VARCHAR2(1) NOT NULL, REQUESTS_RECOVERY VARCHAR2(1) NOT NULL, JOB_DATA BLOB NULL, PRIMARY KEY (JOB_NAME,JOB_GROUP) ) </create> <drop>DROP TABLE QRTZ_JOB_DETAILS</drop> <dialect-scope name='org.hibernate.SomeOracleDialect' /> </database-object> ... <database-object> <create>INSERT INTO QRTZ_LOCKS VALUES('TRIGGER_ACCESS')</create> <drop></drop> <dialect-scope name='org.hibernate.SomeOracleDialect' /> </database-object> ... </hibernate-mapping>
dialect-scope tells Hibernate to use the database to name the create and delete nodes. You can try to leave it and see if it works, otherwise you may have to add the MySql dialogs used by your Grails data source.