Dvora
Dvora

Reputation: 1175

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.

Upvotes: 2

Views: 1368

Answers (3)

Musthafa
Musthafa

Reputation: 1

you can use like this ${org.codehaus.groovy.grails.commons.ConfigurationHolder.config.myJob.name}

Upvotes: 0

rimero
rimero

Reputation: 2383

Try using the Holders helper class.

import grails.util.Holders

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

Upvotes: 7

Eylen
Eylen

Reputation: 2677

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

Upvotes: 0

Related Questions