我在我的应用程序中运行了以下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
祝你好运.如果有帮助,请告诉我.