Grails集群石英工作示例代码和配置所需
我在Grails 1.3.7上使用石英插件。我需要负载平衡/群集使用石英作业的服务器应用程序。显然这是支持的,但我发现所有的谷歌搜索结果和文件内的链接被打破。我已经找到了一些原始的Java示例,但我会认为Grails有一个更加严谨的方式来做到这一点。我需要的只是一个简单的例子来作为模板。我知道我需要以某种方式使石英使用JDBC来存储作业和管理锁定。Grails集群石英工作示例代码和配置所需
我认为一个链接到一个样本就可以了。但从字面上看,每次我找到看起来很有希望的东西时,都会指向兵马俑网站上的一个断开的链接。几乎每个网站最终都会把我带到这里:http://www.opensymphony.com/quartz/wikidocs/TutorialLesson9.html但是当我看到兵马俑的网站时,我看到了Java的东西,但没有看到Grails。如果Java是唯一能做到这一点的方法,那就这样吧,但是我觉得在这个地方必须有一些Grails专业知识!
TIA。
要在Grails中集群Quartz插件,需要在项目中包含一些文件。首先,安装grails-app/conf/QuartzConfig.groovy
并确保jdbcStore
已启用。
quartz {
autoStartup = true
jdbcStore = true
waitForJobsToCompleteOnShutdown = true
}
接下来,安装与您要连接的数据库相关的Hibernate配置文件。例如,与甲骨文在grails-app/conf/hibernate/hibernate.cfg.xml
基地Hibernate的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>
这个例子的实际石英Hibernate的SQL文件将被命名为Quartz.oracle.hbm.xml
,将驻留在同一目录下。这些文件应该在GitHub上的Quartz插件(https://github.com/nebolsin/grails-quartz)下,在src/templates/sql
下。请注意,这些脚本似乎只适用于DataSource create
和create-drop
,因此如果上一次运行中不存在Quartz表,则需要在update
上手动创建Quartz表。
创建grails-app/conf/quartz/quartz.properties
文件,编辑是适合您的业务需求:从上面的性能
/* Have the scheduler id automatically generated for
* all schedulers in a cluster */
org.quartz.scheduler.instanceId = AUTO
/* Don't let Quartz "Phone Home" to see if new versions
* are available */
org.quartz.scheduler.skipUpdateCheck = true
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
/* Configure Quartz for only one thread as the only job
* should run once per day */
org.quartz.threadPool.threadCount = 4
/* Give the thread a Thread.MIN_PRIORITY level*/
org.quartz.threadPool.threadPriority = 1
/* Allow a minute (60,000 ms) of non-firing to pass before
* a trigger is called a misfire */
org.quartz.jobStore.misfireThreshold = 60000
/* Handle only 2 misfired triggers at a time */
org.quartz.jobStore.maxMisfiresToHandleAtATime = 2
/* Check in with the cluster every 5000 ms*/
org.quartz.jobStore.clusterCheckinInterval = 5000
/* Use the Oracle Quartz Driver to communicate via JDBC */
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
/* Have Quartz handle its own transactions with the database */
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
/* Define the prefix for the Quartz tables in the database*/
org.quartz.jobStore.tablePrefix = QRTZ_
/* Tell Quartz it is clustered */
org.quartz.jobStore.isClustered = true
/* Tell Quartz that properties passed to the job call are
* NOT all String objects */
org.quartz.jobStore.useProperties = false
/* Detect the jvm shutdown and call shutdown on the scheduler */
org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownhook.cleanShutdown = true
/* Log the history of triggers and jobs */
org.quartz.plugin.triggerHistory.class = org.quartz.plugins.history.LoggingTriggerHistoryPlugin
org.quartz.plugin.jobHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin
注意,你可以在Config.groovy
Log4j的设置中设置org.quartz.plugins
登录相关的工作,并触发的触发信息。我认为info
级别应该就足够了。
编辑或创建scripts/_Events.groovy
并添加以下war修改闭包。这修复了一个已知的Quartz插件错误,从插件安装正确的quartz.properties
而不是空白的插件,直到最终的war文件。
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")
}
而且你应该做的事...
附:如果您使用的是Oracle数据库,添加以下BuildConfig.groovy
在相关模块,让你有机会获得石英的Oracle通信驱动程序:
runtime("org.quartz-scheduler:quartz-oracle:1.7.2") {
// Exclude quartz as 1.7.3 is included from the plugin
excludes('quartz')
}
PPS上面的链接的sql文件只是SQL。为了使它在一个休眠文件,只是围绕每一个单独的SQL命令一个Hibernate database-object
节点,像这样(再次W /甲骨文为例):
<?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
告诉Hibernate与数据库方言的创建和删除应该使用节点。您可以尝试将其保留并查看它是否有效,否则可能需要添加由Grails数据源使用的MySql方言。
非常感谢你的详细回应。这看起来像我正在寻找的信息。我使用亚马逊的RDS作为MySQL的数据库。再次感谢。 –
我一直无法找到名为Quartz.mysql.innodb.hbm.xml的文件。我找到了tables_mysql_innodb.sql,但是在上面的示例xml代码中,它意味着我应该设置 –
我一直无法找到名为Quartz.mysql.innodb.hbm.xml的文件。我找到了tables_mysql_innodb.sql,但是在上面的示例xml代码中,它意味着我应该设置。我搜查了从github签出的所有代码,并且没有这样的xml文件。我很抱歉,但我对这一切都很陌生。我的数据库是使用InnoDB的亚马逊的RDS MySQL。我想我将不得不深入Quartz和Hibernate配置来理解这一点。我度过了漫长的一天,也许当我在早上看到这一切时,它会更有意义! Thx –