在石英插件中使用grails数据源 [英] Using grails datasources in quartz plugin
问题描述
示例显示了如何使用quartz.properties文件配置quartz。
现在,我希望我的jdbc存储与我的grails应用程序具有相同的数据库,以便我可以减少重复设置。
因此,假设我手动在我的数据库中创建所需的表,是否可以使用Quartas插件在Datasource.groovy中配置的默认dataSource?
我使用的是grails 2.4.4和quartz 1.0.2。
换句话说,我可以添加我的设置到QuartzConfig.groovy而不是创建一个新的quartz.properties文件?至少我可以从单独的环境设置中受益。
在QuartzConfig.groovy中是否有效?
quartz {
autoStartup = true
jdbcStore = true
waitForJobsToCompleteOnShutdown = true
exposeSchedulerInRepository = true
道具{
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'
// [...]
}
我设法调整了QuartzConfig.groovy中的所有设置。我必须删除才能使它工作的是数据库特定的选项。
另外,我必须添加属性 scheduler.idleWaitTime = 1000
这里建议 http://www.quartz-scheduler .org / generated / 2.2.1 / pdf / Quartz_Scheduler_Configuration_Guide.pdf (第12页),因为尽管我的作业被称为 MyJob.triggerNow(paramsMap)
,那么在实际开始之前有20到30秒的延迟。
当 scheduler.idleWaitTime
设置为1秒时, job提交后确实会触发1秒。
QuartzProperties.groovy实际上接受石英配置文档中描述的所有属性(例如:http://quartz-scheduler.org/documentation/quartz-2.1.x/configuration/ConfigJobStoreTX )。只要将它们放入 props {...}
块中,然后移除 org.quartz
前缀即可。
这是我的最终配置,例如:
石英{
autoStartup = true
jdbcStore = true
waitForJobsToCompleteOnShutdown = true
//允许在Java Melody中进行监控(如果您在grails应用程序中安装了java旋律插件)
exposeSchedulerInRepository = true
道具{
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
}
}
不要忘记用适当的方法创建sql表脚本,位于/path/to/your/project/target/work/plugins/quartz-1.0.2/src/templates/sql /...
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'
// [...]
}
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/...
这篇关于在石英插件中使用grails数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!