Quartz job triggering from Config.groovy

前端 未结 2 929
北恋
北恋 2020-12-17 06:48

I have the following Quartz job running in my application:

class ScraperJob {
    def scraperService

    static triggers = {
        cron name: \'scraperTri         


        
相关标签:
2条回答
  • 2020-12-17 06:53

    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.

    0 讨论(0)
  • 2020-12-17 07:05

    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(){ ... }
    }
    
    0 讨论(0)
提交回复
热议问题