Multiple scheduler using grail quartz plugin

余生颓废 提交于 2019-12-12 00:41:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!