问题
I am using grails quartz plugin to implement scheduling in our app. I've created one scheduler with QuartzConfig.groovy props, which is Clustered scheduler. I want one more scheduler in the same app for Non-Clustered scheduling.
How can I achieve this using same grails quartz plugin.
回答1:
I do this creating a new scheduler bean in resources.groovy:
newQuartzScheduler(org.springframework.scheduling.quartz.SchedulerFactoryBean) {
Properties properties = new Properties()
properties.setProperty('org.quartz.threadPool.threadCount', 5)
quartzProperties = properties
autoStartup = false
waitForJobsToCompleteOnShutdown = true
exposeSchedulerInRepository = false
jobFactory = ref('quartzJobFactory')
globalJobListeners = [ref("${SessionBinderJobListener.NAME}"), ref("${ExceptionPrinterJobListener.NAME}")]
}
and add the below code in BootStrap.
newQuartzScheduler.addJob(grailsApplication.mainContext.getBean('org.com.jobs.JobNameJobDetail'), true)
newQuartzScheduler.start()
That 'Detail' in job name is necessary because Quartz plugin create a bean for each job and it includes that suffix at his names.
In my case, I need to have a different queue to execute only one of my jobs.
The quartz plugin add all jobs in your scheduler.
If you need to have all your jobs in both schedulers see doWithApplicationContext in QuartzGrailsPlugin class
来源:https://stackoverflow.com/questions/36941121/multiple-scheduler-using-grail-quartz-plugin