Search code examples
grailsjobs

Grails - getting job trigger values from a config file


In my grials application I have a job that runs, and this its trigger defenition:

    static triggers = {
    simple name: 'myJob', startDelay: 1000, repeatInterval: 36000000   
    }

I would like to change it that the value shouln't be hard coded, but they should be taken from a congif/properties file.

I tried this:

Config.groovy:

myJob {
simpleName = 'myJob'
startDelay = '1000'
repeatInterval = '36000000'
}

and in the job trigger:

    static triggers = {
    simple name: grailsApplication.config.myJob.name, startDelay: grailsApplication.config.myJob.startDelay, repeatInterval: grailsApplication.config.myJob.repeatInterval   
    }

But then I get a message saying: Cannot reference nonstatic symbol 'grailsApplication' from static context.

Does anyone have a better idea how to do so?

Thanks.


Solution

  • I have found also this problem and what I usually do is store the properties in the .properties file, remove the triggers from the Quartz job and then manually bootstrap those jobs in Bootstrap.groovy getting the values from the properties file.

    Check this: Quartz Plugin Documentation to see how to trigger the jobs