Quartz job triggering from Config.groovy

淺唱寂寞╮ 提交于 2019-11-29 05:17:05

I have no idea if this would actually work because i'm not sure when the quartz jobs get configured but in theory it would seem to work. You could probably see how you could also make this much more dynamic if you have more than one job.

Config.groovy

quartz.yourCronJobName="0 0 * * * ?"

BootStrap.groovy

import org.codehaus.groovy.grails.commons.ConfigurationHolder as ConfigHolder
...
def cronExpression = ConfigHolder.config.yourCronJobName
ScraperJob.triggers.cronExpression = cronExpression 

Good luck. Let me know if it helps.

Here is how I eventually did it:

Config.groovy

scraperJob= "0 * * * * ?"

ScraperJob.groovy

import org.codehaus.groovy.grails.commons.ConfigurationHolder as ConfigHolder

class ScraperJob {

  static triggers = {
        cron cronExpression: ConfigHolder.config.scraperJob // Calling the ScraperJob set in Config.groovy
    }
  def execute(){ ... }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!