Permalink
Browse files

version tweaks and clean up

  • Loading branch information...
1 parent 557f506 commit 905bca5a7b7c59d57824a5e9638596141787af86 Joshua Burnett committed Dec 31, 2011
View
@@ -21,15 +21,15 @@ import org.springframework.beans.factory.config.MethodInvokingFactoryBean
class Quartz2GrailsPlugin {
// the plugin version
- def version = "0.2.1.2"
+ def version = "0.2.2"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "1.3 > *"
- // the other plugins this plugin depends on
- def dependsOn = [:]
- // resources that are excluded from plugin packaging
- def pluginExcludes = [
- "grails-app/views/error.gsp"
- ]
+
+ def pluginExcludes = [
+ "grails-app/views/**/*",
+ "grails-app/controllers/**/*",
+ "web-app/**/*"
+ ]
// TODO Fill in these fields
def author = "Joshua Burentt"
@@ -50,6 +50,8 @@ The goal is to keep it as simple as possible while making it friendly for Groovy
def artefacts = [new JobArtefactHandler()]
+ def loadAfter = ['hibernate']
+
def doWithSpring = {
def mcfg = application.mergedConfig
MergedConfigHolder.config = application.mergedConfig
@@ -61,9 +63,9 @@ The goal is to keep it as simple as possible while making it friendly for Groovy
configureJobBeans(jobClass)
}
- persistenceContextJobListener(PersistenceContextJobListener){
- persistenceInterceptor = ref("persistenceInterceptor")
- }
+ // persistenceContextJobListener(PersistenceContextJobListener){
+ // persistenceInterceptor = ref("persistenceInterceptor")
+ // }
jobErrorLoggerListener(JobErrorLoggerListener)
quartzJobFactory(GrailsJobFactory)
@@ -72,9 +74,11 @@ The goal is to keep it as simple as possible while making it friendly for Groovy
grailsApplication = ref('grailsApplication')
quartzProperties = quartzProps
jobFactory = quartzJobFactory
+ // delay scheduler startup to after-bootstrap stage
+ //autoStartup = false
// delay scheduler startup to after-bootstrap stage
autoStartup = mcfg.grails.plugin.quartz2.autoStartup
- globalJobListeners = [ref('jobErrorLoggerListener'),ref('persistenceContextJobListener')]
+ globalJobListeners = [ref('jobErrorLoggerListener')]//,ref('persistenceContextJobListener')]
if (mcfg.grails.plugin.quartz2.jdbcStore) {
dataSource = ref('dataSource')
transactionManager = ref('transactionManager')
@@ -157,16 +161,21 @@ The goal is to keep it as simple as possible while making it friendly for Groovy
def doWithApplicationContext = { ctx ->
- //assert ctx.quartzScheduler
-
- application.jobClasses.each {jobClass ->
- //println "** doWithApplicationContext adding methods to jobClass.getFullName()"
- scheduleJob.delegate = delegate
- scheduleJob(jobClass, ctx)
- }
-
def scheduler = ctx.getBean("quartzScheduler")
if (scheduler) {
+ //do this here so that
+ if(ctx.persistenceInterceptor){
+ def listener = new PersistenceContextJobListener()
+ listener.persistenceInterceptor = ctx.persistenceInterceptor
+ scheduler.listenerManager.addJobListener(listener)
+ }
+
+ application.jobClasses.each {jobClass ->
+ //println "** doWithApplicationContext adding methods to jobClass.getFullName()"
+ scheduleJob.delegate = delegate
+ scheduleJob(jobClass, ctx, scheduler)
+ }
+
if(application.mergedConfig.grails.plugin.quartz2.autoStartup){
def builders = application.mergedConfig.grails.plugin.quartz2.jobSetup.flatten()
if(builders?.keySet()){
@@ -210,34 +219,29 @@ The goal is to keep it as simple as possible while making it friendly for Groovy
// event.ctx.registerBeanDefinition("${name}Trigger", beans.getBeanDefinition("${name}Trigger"))
// }
- scheduleJob(jobClass, event.ctx)
+ scheduleJob(jobClass, event.ctx, scheduler)
} else {
log.error("Application context or Quartz Scheduler not found. Can't reload Quartz plugin.")
}
}
}
- def scheduleJob = {GrailsJobClass jobClass, ApplicationContext ctx ->
- def scheduler = ctx.getBean("quartzScheduler")
- if (scheduler) {
- def fullName = jobClass.fullName
- // add job to scheduler, and associate triggers with it
- def jobDetail = ctx.getBean("${fullName}Detail")
- scheduler.addJob(jobDetail, true)
- jobClass.triggers.each {key, trigger ->
- //println("Scheduling $fullName with trigger $key: ${trigger} with name:${trigger.triggerAttributes.name}")
- def tkey = new TriggerKey(trigger.triggerAttributes.name,trigger.triggerAttributes.group)
- def trigInstance = TriggersBuilder.createTrigger(trigger,jobDetail.key)
- if (scheduler.getTrigger(tkey)) {
- scheduler.rescheduleJob(tkey, trigInstance)
- } else {
- scheduler.scheduleJob(trigInstance)
- }
- }
- //println("Job ${jobClass.fullName} scheduled")
- } else {
- log.error("Failed to register job triggers: scheduler not found")
- }
+ def scheduleJob = {GrailsJobClass jobClass, ctx, scheduler ->
+
+ def fullName = jobClass.fullName
+ // add job to scheduler, and associate triggers with it
+ def jobDetail = ctx.getBean("${fullName}Detail")
+ scheduler.addJob(jobDetail, true)
+ jobClass.triggers.each {key, trigger ->
+ //println("Scheduling $fullName with trigger $key: ${trigger} with name:${trigger.triggerAttributes.name}")
+ def tkey = new TriggerKey(trigger.triggerAttributes.name,trigger.triggerAttributes.group)
+ def trigInstance = TriggersBuilder.createTrigger(trigger,jobDetail.key)
+ if (scheduler.getTrigger(tkey)) {
+ scheduler.rescheduleJob(tkey, trigInstance)
+ } else {
+ scheduler.scheduleJob(trigInstance)
+ }
+ }
}
def configureJobBeans = {GrailsJobClass jobClass ->
View
@@ -7,7 +7,7 @@ Uses the new [Quartz][] 2.1 framework from quartz-scheduler.org. The goal is to
* Its mostly backward compatible with the original [Quartz plugin][] so its allows scheduling jobs using job artifacts as well. See note below for areas where it is not compatible.
* Uses a factory to creates a single bean called quartzScheduler which is a standard Quartz [Scheduler][] and starts it. Its does not start it by default in test. You can inject and use the quartzScheduler bean like any normal Grails/Spring bean.
* All quartz settings can be done in Config.groovy, thus eliminating the need for a quartz.properties
-* Sets up a PersistenceContextJobListener, makes it a bean and adds it to the scheduler. This wraps all the jobs to make sure they have a hibernate session bound to the thread or if using another (nosql) engine then this should work for other non-hibernate gorm engines too as it uses the "persistenceInterceptor" bean to init(). If you don't need gorm persistence in your job then you can avoid the overhead and turn it of by assigning a "gormSession:false" property in the the JobDataMap when setting up a [JobDetail][] or Trigger. Note:
+* Sets up a PersistenceContextJobListener, makes it a bean and adds it to the scheduler. This wraps all the jobs to make sure they have a hibernate session bound to the thread or if using another (nosql) engine like Mongo or Redis then this should work too as it uses the "persistenceInterceptor" bean to init(). If you don't need gorm persistence in your job then you can avoid the overhead and turn it of by assigning a "gormSession:false" property in the the JobDataMap when setting up a [JobDetail][] or Trigger. Note:
* adds a general InvokeMethodJob class that can be used to setup a [JobDetail][] to calls a service bean method or any static or local method on a passed in object
* support for assigning a builder closures in Config.groovy (or an externalized config) that will get called on application startup to setup your scheduler
* Adds a SimpleJobDetail - an implementation of the JobDetail that makes it easier to setDisallowConcurrentExecution with the need to put the annotaion on the Job class. Also makes it much easier to add JobDataMap properties by simply passing a map into the constructor
@@ -31,7 +31,7 @@ grails.project.dependency.resolution = {
}
plugins {
compile ':plugin-config:0.1.5'
- build(":tomcat:$grailsVersion", ":release:1.0.0", ":hibernate:$grailsVersion") {
+ build(":tomcat:$grailsVersion", ":release:1.0.0"){//, ":hibernate:$grailsVersion") {
export = false
}
@@ -38,7 +38,7 @@ class QuartzPluginTests extends GroovyTestCase implements ApplicationContextAwar
assertTrue 'Quartz plugin is not loaded', pluginManager.hasGrailsPlugin('quartz2')
assertTrue "Bean 'quartzScheduler' is not registered in application context", applicationContext.containsBean('quartzScheduler')
- assertTrue "Bean sessionBinderJobListener is not registered in application context", applicationContext.containsBean('persistenceContextJobListener')
+ //assertTrue "Bean sessionBinderJobListener is not registered in application context", applicationContext.containsBean('persistenceContextJobListener')
assertTrue "Bean exceptionPrinterJobListener is not registered in application context", applicationContext.containsBean('jobErrorLoggerListener')
}

0 comments on commit 905bca5

Please sign in to comment.