Invoking a Service from Quartz2

gbelin

New member
Hi there,

I'm not able to call a service from a job in Quartz2 plugin. I have a service named "CheckDepartmentEmployeesService" with a method named "doCheck", and I the file ""QuartzConfig.groovy" like this




import static org.quartz.JobBuilder.*;
import static org.quartz.SimpleScheduleBuilder.*;
import static org.quartz.TriggerBuilder.*;
import grails.plugin.quartz2.InvokeMethodJob
import org.quartz.JobDataMap
import org.quartz.JobDetail
import org.quartz.Trigger
import org.quartz.impl.triggers.SimpleTriggerImpl

grails.plugin.quartz2.autoStartup = true
org{
quartz{
scheduler.instanceName = 'MyScheduler'
threadPool.class = 'org.quartz.simpl.SimpleThreadPool'
threadPool.threadCount = 20
threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
jobStore.class = 'org.quartz.simpl.RAMJobStore'
}
}


grails.plugin.quartz2.jobSetup.mySchedule = { quartzScheduler, ctx ->
def props = new JobDataMap([targetObject:ctx.checkDepartmentEmployeesService,targetMethod:'doCheck',arguments:[true]])
JobDetail jobDetail = newJob(InvokeMethodJob.class)
.withIdentity("perform my action")
.usingJobData(props)
.build()


Trigger trigger = newTrigger().withIdentity("doCheck trigger")
.withSchedule(
simpleSchedule().repeatSecondlyForTotalCount(5, 3)
)
.startNow().build()

quartzScheduler.scheduleJob(jobDetail, trigger)
}




Thanks in advance.
 
Top