Grails - using property value for cron expression in scheduled job -
this question has answer here:
- quartz job triggering config.groovy 2 answers
am using quartz plugin grails , have simple job:
class myjob{ static triggers = { cron name: 'myjobtrigger', cronexpression: '0 0/1 * * * ?' } def execute(){ println "do work" } }
all works fine, job fires off every minute expected.
now want want cron expression property driven can override in different environments. config.groovy contains default value:
myjob.cron = '0 0/1 * * * * ?'
and change class have:
grailsapplication grailsapplication static triggers = { cron name: 'myjobtrigger', cronexpression: grailsapplication.config.myjob.cron }
when run code, error:
caused missingpropertyexception: no such property: grailsapplication class: myjob
assuming way myjob class loaded/initialised, static triggers created before grailsapplication injected??? use of grailsapplication usual way project properties.
how else can have property driven cron trigger?
i just ran this, , adding scheduling bootstrap.groovy worked fine. in myjob class, set triggers empty closure:
class myjob { static triggers = { // job scheduled in bootstrap.groovy can externalized } def execute() { println "do work" } }
then in bootstrap.groovy file, set this:
class bootstrap { def grailsapplication def init = { servletcontext -> myjob.schedule(grailsapplication.config.myjob.cron) } }
Comments
Post a Comment