Permalink
Browse files

Change generic "Job" artefact to "JesqueJob".

Address issue #14 where jesque is in conflict with other plugging (e.g. quartz) that use the name "Job" for artefact types.
  • Loading branch information...
1 parent da3d6c0 commit a721e1de75d1dc1e1323b58328e32b0203612159 @michaelcameron committed Jun 1, 2012
View
@@ -1,5 +1,5 @@
-import grails.plugin.jesque.GrailsJobClass
-import grails.plugin.jesque.JobArtefactHandler
+import grails.plugin.jesque.GrailsJesqueJobClass
+import grails.plugin.jesque.JesqueJobArtefactHandler
import net.greghaines.jesque.Config
import net.greghaines.jesque.ConfigBuilder
import net.greghaines.jesque.client.ClientPoolImpl
@@ -47,7 +47,7 @@ class JesqueGrailsPlugin {
"file:./plugins/*/grails-app/jobs/**/*Job.groovy"
]
- def artefacts = [new JobArtefactHandler()]
+ def artefacts = [new JesqueJobArtefactHandler()]
def doWithWebDescriptor = { xml ->
}
@@ -84,19 +84,19 @@ class JesqueGrailsPlugin {
workerInfoDao(WorkerInfoDAORedisImpl, ref('jesqueConfig'), ref('redisPool'))
log.info "Creating jesque job beans"
- application.jobClasses.each {jobClass ->
+ application.jesqueJobClasses.each {jobClass ->
configureJobBeans.delegate = delegate
configureJobBeans(jobClass)
}
}
- def configureJobBeans = {GrailsJobClass jobClass ->
+ def configureJobBeans = {GrailsJesqueJobClass jobClass ->
def fullName = jobClass.fullName
"${fullName}Class"(MethodInvokingFactoryBean) {
targetObject = ref("grailsApplication", true)
targetMethod = "getArtefact"
- arguments = [JobArtefactHandler.TYPE, jobClass.fullName]
+ arguments = [JesqueJobArtefactHandler.TYPE, jobClass.fullName]
}
"${fullName}"(ref("${fullName}Class")) {bean ->
@@ -113,7 +113,7 @@ class JesqueGrailsPlugin {
JesqueConfigurationService jesqueConfigurationService = applicationContext.jesqueConfigurationService
log.info "Scheduling Jesque Jobs"
- application.jobClasses.each{ GrailsJobClass jobClass ->
+ application.jesqueJobClasses.each{ GrailsJesqueJobClass jobClass ->
jesqueConfigurationService.scheduleJob(jobClass)
}
@@ -146,7 +146,7 @@ class JesqueGrailsPlugin {
def onChange = {event ->
Class source = event.source
- if(!application.isArtefactOfType(JobArtefactHandler.TYPE, source)) {
+ if(!application.isArtefactOfType(JesqueJobArtefactHandler.TYPE, source)) {
return
}
@@ -156,11 +156,11 @@ class JesqueGrailsPlugin {
JesqueConfigurationService jesqueConfigurationService = context?.jesqueConfigurationService
if(context && jesqueConfigurationService) {
- GrailsJobClass jobClass = application.getJobClass(source.name)
+ GrailsJesqueJobClass jobClass = application.getJobClass(source.name)
if(jobClass)
jesqueConfigurationService.deleteScheduleJob(jobClass)
- jobClass = (GrailsJobClass)application.addArtefact(JobArtefactHandler.TYPE, source)
+ jobClass = (GrailsJesqueJobClass)application.addArtefact(JesqueJobArtefactHandler.TYPE, source)
beans {
configureJobBeans.delegate = delegate
@@ -29,7 +29,7 @@ class JesqueConfigurationService {
}
void mergeClassConfigurationIntoConfigMap(ConfigObject jesqueConfigMap) {
- grailsApplication.jobClasses.each { GrailsJobClass jobArtefact ->
+ grailsApplication.jesqueJobClasses.each { GrailsJesqueJobClass jobArtefact ->
def alreadyConfiguredPool = jesqueConfigMap.workers.find{ poolName, poolConfig ->
poolConfig.jobTypes.any{ jobName, jobClassValue ->
jobClassValue == jobArtefact.clazz
@@ -38,13 +38,13 @@ class JesqueConfigurationService {
if( alreadyConfiguredPool ) {
//already configured, make sure pool name matches, and queue is listed, otherwise error, do nothing else
- if( jobArtefact.workerPool != GrailsJobClassProperty.DEFAULT_WORKER_POOL && jobArtefact.workerPool != alreadyConfiguredPool.getKey() )
+ if( jobArtefact.workerPool != GrailsJesqueJobClassProperty.DEFAULT_WORKER_POOL && jobArtefact.workerPool != alreadyConfiguredPool.getKey() )
throw new Exception("Class ${jobArtefact.fullName} specifies worker pool ${jobArtefact.workerPool} but configuration file has ${alreadyConfiguredPool.getKey()}")
if( alreadyConfiguredPool.value.queueNames instanceof String )
alreadyConfiguredPool.value.queueNames = [alreadyConfiguredPool.value.queueNames]
- if( jobArtefact.queue != GrailsJobClassProperty.DEFAULT_QUEUE && !(jobArtefact.queue in alreadyConfiguredPool.value.queueNames) )
+ if( jobArtefact.queue != GrailsJesqueJobClassProperty.DEFAULT_QUEUE && !(jobArtefact.queue in alreadyConfiguredPool.value.queueNames) )
throw new Exception("Class ${jobArtefact.fullName} specifies queue name ${jobArtefact.queue} but worker pool ${alreadyConfiguredPool.getKey()} has ${alreadyConfiguredPool.value.queueNames}")
return
@@ -68,26 +68,26 @@ class JesqueConfigurationService {
}
}
- void scheduleJob(GrailsJobClass jobClass) {
+ void scheduleJob(GrailsJesqueJobClass jobClass) {
log.info("Scheduling ${jobClass.fullName}")
jobClass.triggers.each {key, trigger ->
- String name = trigger.triggerAttributes[GrailsJobClassProperty.NAME]
- String cronExpression = trigger.triggerAttributes[GrailsJobClassProperty.CRON_EXPRESSION]
- DateTimeZone timeZone = DateTimeZone.forID(trigger.triggerAttributes[GrailsJobClassProperty.TIMEZONE])
- String queue = trigger.triggerAttributes[GrailsJobClassProperty.JESQUE_QUEUE]
- String jesqueJobName = trigger.triggerAttributes[GrailsJobClassProperty.JESQUE_JOB_NAME]
- List jesqueJobArguments = trigger.triggerAttributes[GrailsJobClassProperty.JESQUE_JOB_ARGUMENTS] ?: []
+ String name = trigger.triggerAttributes[GrailsJesqueJobClassProperty.NAME]
+ String cronExpression = trigger.triggerAttributes[GrailsJesqueJobClassProperty.CRON_EXPRESSION]
+ DateTimeZone timeZone = DateTimeZone.forID(trigger.triggerAttributes[GrailsJesqueJobClassProperty.TIMEZONE])
+ String queue = trigger.triggerAttributes[GrailsJesqueJobClassProperty.JESQUE_QUEUE]
+ String jesqueJobName = trigger.triggerAttributes[GrailsJesqueJobClassProperty.JESQUE_JOB_NAME]
+ List jesqueJobArguments = trigger.triggerAttributes[GrailsJesqueJobClassProperty.JESQUE_JOB_ARGUMENTS] ?: []
jesqueSchedulerService.schedule(name, cronExpression, timeZone, queue, jesqueJobName, jesqueJobArguments)
}
}
- void deleteScheduleJob(GrailsJobClass jobClass) {
+ void deleteScheduleJob(GrailsJesqueJobClass jobClass) {
log.info("Remove schedule for ${jobClass.fullName}")
jobClass.triggers.each {key, trigger ->
- String name = trigger.triggerAttributes[GrailsJobClassProperty.NAME]
+ String name = trigger.triggerAttributes[GrailsJesqueJobClassProperty.NAME]
jesqueSchedulerService.deleteSchedule(name)
}
@@ -4,11 +4,11 @@ import org.joda.time.DateTimeZone
public class TriggersConfigBuilder extends BuilderSupport {
private Integer triggerNumber = 0
- private GrailsJobClass jobClass
+ private GrailsJesqueJobClass jobClass
def triggers = [:]
- public TriggersConfigBuilder(GrailsJobClass jobClass) {
+ public TriggersConfigBuilder(GrailsJesqueJobClass jobClass) {
super()
this.jobClass = jobClass
}
@@ -40,20 +40,20 @@ public class TriggersConfigBuilder extends BuilderSupport {
}
private prepareCommonTriggerAttributes(Map triggerAttributes) {
- if(triggerAttributes[GrailsJobClassProperty.NAME] == null)
- triggerAttributes[GrailsJobClassProperty.NAME] = "${jobClass.fullName}${triggerNumber++}"
+ if(triggerAttributes[GrailsJesqueJobClassProperty.NAME] == null)
+ triggerAttributes[GrailsJesqueJobClassProperty.NAME] = "${jobClass.fullName}${triggerNumber++}"
- if(triggerAttributes[GrailsJobClassProperty.JESQUE_JOB_NAME] == null) {
- triggerAttributes[GrailsJobClassProperty.JESQUE_JOB_NAME] = jobClass.jobNames.first()
+ if(triggerAttributes[GrailsJesqueJobClassProperty.JESQUE_JOB_NAME] == null) {
+ triggerAttributes[GrailsJesqueJobClassProperty.JESQUE_JOB_NAME] = jobClass.jobNames.first()
}
- if(triggerAttributes[GrailsJobClassProperty.JESQUE_QUEUE] == null) {
- triggerAttributes[GrailsJobClassProperty.JESQUE_QUEUE] = jobClass.queue
+ if(triggerAttributes[GrailsJesqueJobClassProperty.JESQUE_QUEUE] == null) {
+ triggerAttributes[GrailsJesqueJobClassProperty.JESQUE_QUEUE] = jobClass.queue
}
- if(triggerAttributes[GrailsJobClassProperty.JESQUE_JOB_ARGUMENTS] != null
- && !(triggerAttributes[GrailsJobClassProperty.JESQUE_JOB_ARGUMENTS] instanceof List))
- throw new Exception("If ${GrailsJobClassProperty.JESQUE_JOB_ARGUMENTS} exists, it must be a list");
+ if(triggerAttributes[GrailsJesqueJobClassProperty.JESQUE_JOB_ARGUMENTS] != null
+ && !(triggerAttributes[GrailsJesqueJobClassProperty.JESQUE_JOB_ARGUMENTS] instanceof List))
+ throw new Exception("If ${GrailsJesqueJobClassProperty.JESQUE_JOB_ARGUMENTS} exists, it must be a list");
}
public Expando createTrigger(name, Map attributes, value) {
@@ -75,20 +75,20 @@ public class TriggersConfigBuilder extends BuilderSupport {
}
private def prepareCronTriggerAttributes(Map triggerAttributes) {
- if(!triggerAttributes[GrailsJobClassProperty.CRON_EXPRESSION])
+ if(!triggerAttributes[GrailsJesqueJobClassProperty.CRON_EXPRESSION])
throw new Exception("Cron trigger must have 'cronExpression' attribute")
- if(!CronExpression.isValidExpression(triggerAttributes[GrailsJobClassProperty.CRON_EXPRESSION].toString()))
- throw new Exception("Cron expression '${triggerAttributes[GrailsJobClassProperty.CRON_EXPRESSION]}' in the job class ${jobClass.fullName} is not a valid cron expression");
+ if(!CronExpression.isValidExpression(triggerAttributes[GrailsJesqueJobClassProperty.CRON_EXPRESSION].toString()))
+ throw new Exception("Cron expression '${triggerAttributes[GrailsJesqueJobClassProperty.CRON_EXPRESSION]}' in the job class ${jobClass.fullName} is not a valid cron expression");
- if(triggerAttributes[GrailsJobClassProperty.TIMEZONE]) {
+ if(triggerAttributes[GrailsJesqueJobClassProperty.TIMEZONE]) {
try {
- DateTimeZone.forID(triggerAttributes[GrailsJobClassProperty.TIMEZONE])
+ DateTimeZone.forID(triggerAttributes[GrailsJesqueJobClassProperty.TIMEZONE])
} catch(Exception exception) {
- throw new Exception("Invalid ${GrailsJobClassProperty.TIMEZONE} on cron trigger", exception)
+ throw new Exception("Invalid ${GrailsJesqueJobClassProperty.TIMEZONE} on cron trigger", exception)
}
} else {
- triggerAttributes[GrailsJobClassProperty.TIMEZONE] = DateTimeZone.default.ID
+ triggerAttributes[GrailsJesqueJobClassProperty.TIMEZONE] = DateTimeZone.default.ID
}
}
@@ -9,13 +9,13 @@
import java.util.List;
import java.util.Map;
-public class DefaultGrailsJobClass extends AbstractInjectableGrailsClass implements GrailsJobClass {
+public class DefaultGrailsJesqueJobClass extends AbstractInjectableGrailsClass implements GrailsJesqueJobClass {
public static final String JOB = "Job";
private Map triggers = new HashMap();
- public DefaultGrailsJobClass(Class clazz) {
+ public DefaultGrailsJesqueJobClass(Class clazz) {
super(clazz, JOB);
evaluateTriggers();
}
@@ -37,22 +37,22 @@ public Map getTriggers() {
}
public String getQueue() {
- String queue = (String)getPropertyValue(GrailsJobClassProperty.QUEUE);
+ String queue = (String)getPropertyValue(GrailsJesqueJobClassProperty.QUEUE);
if( queue == null )
- queue = GrailsJobClassProperty.DEFAULT_QUEUE;
+ queue = GrailsJesqueJobClassProperty.DEFAULT_QUEUE;
return queue;
}
public String getWorkerPool() {
- String workerPool = (String)getPropertyValue(GrailsJobClassProperty.WORKER_POOL);
+ String workerPool = (String)getPropertyValue(GrailsJesqueJobClassProperty.WORKER_POOL);
if( workerPool == null )
- workerPool = GrailsJobClassProperty.DEFAULT_WORKER_POOL;
+ workerPool = GrailsJesqueJobClassProperty.DEFAULT_WORKER_POOL;
return workerPool;
}
public List getJobNames() {
- List jobNames = (List)getPropertyValue(GrailsJobClassProperty.JOB_NAMES);
+ List jobNames = (List)getPropertyValue(GrailsJesqueJobClassProperty.JOB_NAMES);
if( jobNames == null || jobNames.size() == 0 )
jobNames = Arrays.asList(getClazz().getName(), getClazz().getSimpleName() );
return jobNames;
@@ -5,7 +5,7 @@
import java.util.List;
import java.util.Map;
-public interface GrailsJobClass extends InjectableGrailsClass {
+public interface GrailsJesqueJobClass extends InjectableGrailsClass {
public Map getTriggers();
@@ -1,6 +1,6 @@
package grails.plugin.jesque;
-public class GrailsJobClassProperty {
+public class GrailsJesqueJobClassProperty {
public static final String CRON_EXPRESSION = "cronExpression";
public static final String JESQUE_JOB_NAME = "jesqueJobName";
@@ -4,18 +4,18 @@
import java.lang.reflect.Method;
-public class JobArtefactHandler extends ArtefactHandlerAdapter {
+public class JesqueJobArtefactHandler extends ArtefactHandlerAdapter {
- public static final String TYPE = "Job";
+ public static final String TYPE = "JesqueJob";
public static final String PERFORM = "perform";
- public JobArtefactHandler() {
- super(TYPE, GrailsJobClass.class, DefaultGrailsJobClass.class, null);
+ public JesqueJobArtefactHandler() {
+ super(TYPE, GrailsJesqueJobClass.class, DefaultGrailsJesqueJobClass.class, null);
}
public boolean isArtefactClass(Class clazz) {
- // class shouldn't be null and shoud ends with Job suffix
- if(clazz == null || !clazz.getName().endsWith(DefaultGrailsJobClass.JOB))
+ // class shouldn't be null and should end with Job suffix
+ if(clazz == null || !clazz.getName().endsWith(DefaultGrailsJesqueJobClass.JOB))
return false;
// and should have a perform() method with any signature
@@ -4,7 +4,6 @@ import grails.plugin.spock.IntegrationSpec
import grails.plugin.jesque.test.SelfConfiguredJob
import grails.plugin.jesque.test.SimpleJob
import grails.plugin.jesque.test.ScheduledTestJob
-import org.joda.time.DateTimeZone
class JesqueConfigurationServiceSpec extends IntegrationSpec{
@@ -93,15 +92,15 @@ class JesqueConfigurationServiceSpec extends IntegrationSpec{
then:
noExceptionThrown()
- config.grails.jesque.workers[GrailsJobClassProperty.DEFAULT_WORKER_POOL]
- config.grails.jesque.workers[GrailsJobClassProperty.DEFAULT_WORKER_POOL].queueNames == [GrailsJobClassProperty.DEFAULT_QUEUE]
- config.grails.jesque.workers[GrailsJobClassProperty.DEFAULT_WORKER_POOL].jobTypes.containsKey(SimpleJob.canonicalName)
- config.grails.jesque.workers[GrailsJobClassProperty.DEFAULT_WORKER_POOL].jobTypes.containsKey(SimpleJob.name)
+ config.grails.jesque.workers[GrailsJesqueJobClassProperty.DEFAULT_WORKER_POOL]
+ config.grails.jesque.workers[GrailsJesqueJobClassProperty.DEFAULT_WORKER_POOL].queueNames == [GrailsJesqueJobClassProperty.DEFAULT_QUEUE]
+ config.grails.jesque.workers[GrailsJesqueJobClassProperty.DEFAULT_WORKER_POOL].jobTypes.containsKey(SimpleJob.canonicalName)
+ config.grails.jesque.workers[GrailsJesqueJobClassProperty.DEFAULT_WORKER_POOL].jobTypes.containsKey(SimpleJob.name)
}
void "test scheduleJob for grails artefact class"() {
given:
- GrailsJobClass jobArtefactClass = grailsApplication.getArtefact(DefaultGrailsJobClass.JOB, ScheduledTestJob.class.name)
+ GrailsJesqueJobClass jobArtefactClass = grailsApplication.getArtefact(JesqueJobArtefactHandler.TYPE, ScheduledTestJob.class.name)
when:
jesqueConfigurationService.scheduleJob(jobArtefactClass)

0 comments on commit a721e1d

Please sign in to comment.