加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

grails – 来自Config.groovy的Quartz作业触发

发布时间:2020-12-14 16:36:09 所属栏目:大数据 来源:网络整理
导读:我在我的应用程序中运行了以下Quartz作业: class ScraperJob { def scraperService static triggers = { cron name: 'scraperTrigger',cronExpression: "0 0 * * * ?" // run every minute } def execute(){ try { scraperService.storing() log.info "${ne
我在我的应用程序中运行了以下Quartz作业:

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属性.如果是的话,你能解释一下吗?

解决方法

我不知道这是否真的有效,因为我不确定什么时候石英作业配置但理论上它似乎工作.如果您有多个工作,您可能会看到如何使这更加动态.

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

祝你好运.如果有帮助,请告诉我.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读