从 Config.groovy 触发 Quartz 作业 [英] Quartz job triggering from Config.groovy

查看:21
本文介绍了从 Config.groovy 触发 Quartz 作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中正在运行以下 Quartz 作业:

I have the following Quartz job running in my application:

class ScraperJob {
    def scraperService

    static triggers = {
        cron name: 'scraperTrigger', cronExpression: "0 0 * * * ?"  // run every minute
    }

    def execute(){
        try {
            scraperService.storing()
            log.info "${new Date()} - Scraping went smoothly."
        }
        catch(IOException) { // Connexion problem
            log.error "${new Date()} - Method: parsing >> Connexion down or interrupted while parsing !"
        }
        catch(SAXException) { // Any SAXParser exception
            log.error "${new Date()} - Method: parsing >> Parser error."
        }
        finally { // if not closed, the application crashes when the connexion fails
            scraperService.slurper.finalize()
            scraperService.parser.finalize()
        }
  }
}

我想知道是否可以从 Config.groovy 文件中设置 triggers 属性.如果是,你能解释一下吗?

I would like to know if it is possible to set the triggers property from the Config.groovy file. If it is, could you explain how?

推荐答案

我不知道这是否真的有效,因为我不确定何时配置石英作业,但理论上它似乎有效.如果您有不止一份工作,您可能会看到如何让这件事变得更有活力.

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

Config.groovy

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

BootStrap.groovy

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.

这篇关于从 Config.groovy 触发 Quartz 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆