Grails - using property value for cron expression in scheduled job -


this question has answer here:

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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -