Ale*_*ier 2 cron grails quartz-scheduler grails-plugin grails-config
我在我的应用程序中运行了以下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()
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否可以triggers从Config.groovy文件中设置属性.如果是的话,你能解释一下吗?
我不知道这是否真的有效,因为我不确定什么时候石英作业配置,但理论上它似乎工作.如果您有多个工作,您可能会看到如何使这更加动态.
Config.groovy中
quartz.yourCronJobName="0 0 * * * ?"
Run Code Online (Sandbox Code Playgroud)
BootStrap.groovy中
import org.codehaus.groovy.grails.commons.ConfigurationHolder as ConfigHolder
...
def cronExpression = ConfigHolder.config.yourCronJobName
ScraperJob.triggers.cronExpression = cronExpression
Run Code Online (Sandbox Code Playgroud)
祝好运.如果有帮助,请告诉我.
| 归档时间: |
|
| 查看次数: |
4485 次 |
| 最近记录: |