Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #17 from chupakabr/issue-16

Fix for issue #16
  • Loading branch information...
commit 17a122d8ecdf104dac9aa996e4b598869cf376e1 2 parents d945738 + 808bf61
@basejump basejump authored
View
11 Quartz2GrailsPlugin.groovy
@@ -63,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")
- // }
+ quartzPersistenceContextJobListener(PersistenceContextJobListener){
+ persistenceInterceptor = ref("persistenceInterceptor")
+ }
jobErrorLoggerListener(JobErrorLoggerListener)
quartzJobFactory(GrailsJobFactory)
@@ -78,7 +78,7 @@ The goal is to keep it as simple as possible while making it friendly for Groovy
//autoStartup = false
// delay scheduler startup to after-bootstrap stage
autoStartup = mcfg.grails.plugin.quartz2.autoStartup
- globalJobListeners = [ref('jobErrorLoggerListener')]//,ref('persistenceContextJobListener')]
+ globalJobListeners = [ref('jobErrorLoggerListener')]//,ref('quartzPersistenceContextJobListener')]
if (mcfg.grails.plugin.quartz2.jdbcStore) {
dataSource = ref('dataSource')
transactionManager = ref('transactionManager')
@@ -165,7 +165,8 @@ The goal is to keep it as simple as possible while making it friendly for Groovy
if (scheduler) {
//do this here so that
if(ctx.persistenceInterceptor){
- def listener = new PersistenceContextJobListener()
+ PersistenceContextJobListener listener = ctx.getBean("quartzPersistenceContextJobListener")
+ //def listener = new PersistenceContextJobListener()
listener.persistenceInterceptor = ctx.persistenceInterceptor
scheduler.listenerManager.addJobListener(listener)
}
View
20 src/groovy/grails/plugin/quartz2/GrailsArtefactJobDetailFactoryBean.groovy
@@ -16,12 +16,8 @@
package grails.plugin.quartz2;
-import org.quartz.JobDetail;
-import org.quartz.JobKey;
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.annotation.Required;
-import org.springframework.scheduling.quartz.SchedulerFactoryBean;
+import org.springframework.beans.factory.FactoryBean
+import org.springframework.beans.factory.InitializingBean
/**
*
@@ -49,8 +45,18 @@ public class GrailsArtefactJobDetailFactoryBean implements FactoryBean, Initiali
// Build JobDetail instance.
jobDetail = new SimpleJobDetail();
jobDetail.setKey(grailsJobClass.getJobKey());
- jobDetail.setJobClass(GrailsArtefactJob.class);
jobDetail.setConcurrent(grailsJobClass.isConcurrent());
+
+ // Different artefacts for concurrent job and non-concurrent job so it will work with
+ // clustered persistent job store like org.quartz.impl.jdbcjobstore.JobStoreTX and
+ // driver delegate like org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
+ if (grailsJobClass.isConcurrent()) {
+ jobDetail.setJobClass(GrailsArtefactJob.class);
+ }
+ else {
+ jobDetail.setJobClass(GrailsArtefactNonConcurrentJob.class);
+ }
+
jobDetail.getJobDataMap().put(JOB_NAME_PARAMETER, grailsJobClass.getFullName());
//FIXME put the check for sessionRequired
View
11 src/java/grails/plugin/quartz2/GrailsArtefactNonConcurrentJob.java
@@ -0,0 +1,11 @@
+package grails.plugin.quartz2;
+
+import org.quartz.DisallowConcurrentExecution;
+
+@DisallowConcurrentExecution
+class GrailsArtefactNonConcurrentJob extends GrailsArtefactJob {
+
+ public GrailsArtefactNonConcurrentJob(Object job) {
+ super(job);
+ }
+}
View
8 src/java/grails/plugin/quartz2/GrailsJobFactory.java
@@ -41,10 +41,14 @@ public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws Schedul
//JobDetail jobDetail = bundle.getJobDetail();
//Class<? extends Job> jobClass = jobDetail.getJobClass();
- String grailsJobName = (String) bundle.getJobDetail().getJobDataMap().get(GrailsArtefactJobDetailFactoryBean.JOB_NAME_PARAMETER);
+ JobDetail jobDetail = bundle.getJobDetail();
+ String grailsJobName = (String) jobDetail.getJobDataMap().get(GrailsArtefactJobDetailFactoryBean.JOB_NAME_PARAMETER);
if (grailsJobName != null) {
Object job = applicationContext.getBean(grailsJobName);
- return new GrailsArtefactJob(job);
+ if (!jobDetail.isConcurrentExectionDisallowed()) {
+ return new GrailsArtefactNonConcurrentJob(job);
+ }
+ return new GrailsArtefactJob(job);
} else {
return super.newJob(bundle,scheduler);
}
View
59 test/unit/grails/plugin/quartz2/GrailsArtefactJobDetailFactoryBeanTests.groovy
@@ -0,0 +1,59 @@
+
+
+package grails.plugin.quartz2
+
+import grails.test.GrailsMock
+import grails.test.mixin.*
+import grails.test.mixin.support.*
+
+import org.junit.*
+import org.quartz.JobKey
+
+/**
+ * See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
+ */
+@TestMixin(GrailsUnitTestMixin)
+class GrailsArtefactJobDetailFactoryBeanTests {
+
+ void setUp() {
+ // Setup logic here
+ }
+
+ void tearDown() {
+ // Tear down logic here
+ }
+
+ void testConcurrentJobCreation() {
+ def jobClassMock = new GrailsMock(GrailsJobClass, true)
+ jobClassMock.demand.getJobKey(1) { return new JobKey("111") }
+ jobClassMock.demand.isConcurrent(2) { return true }
+ jobClassMock.demand.getFullName(1) { return "myfullname" }
+ jobClassMock.demand.isSessionRequired(1) { return true }
+ jobClassMock.demand.isGormSession(1) { return true }
+ jobClassMock.demand.getDurability(1) { return true }
+ jobClassMock.demand.getRequestsRecovery(1) { return true }
+
+ def factory = new GrailsArtefactJobDetailFactoryBean()
+ factory.grailsJobClass = jobClassMock.createMock()
+ factory.afterPropertiesSet()
+
+ assert factory.getObject().getJobClass() == GrailsArtefactJob.class
+ }
+
+ void testNonConcurrentJobCreation() {
+ def jobClassMock = new GrailsMock(GrailsJobClass, true)
+ jobClassMock.demand.getJobKey(1) { return new JobKey("111") }
+ jobClassMock.demand.isConcurrent(2) { return false }
+ jobClassMock.demand.getFullName(1) { return "myfullname" }
+ jobClassMock.demand.isSessionRequired(1) { return true }
+ jobClassMock.demand.isGormSession(1) { return true }
+ jobClassMock.demand.getDurability(1) { return true }
+ jobClassMock.demand.getRequestsRecovery(1) { return true }
+
+ def factory = new GrailsArtefactJobDetailFactoryBean()
+ factory.grailsJobClass = jobClassMock.createMock()
+ factory.afterPropertiesSet()
+
+ assert factory.getObject().getJobClass() == GrailsArtefactNonConcurrentJob.class
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.