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

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

问题描述

我有以下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.

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

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