Tuesday, 22 May 2012

Getting the quartz2 plugin to work with Grails

My app needs to run a job periodically, and I got the quartz2 plugin https://github.com/9ci/grails-quartz2 with one caveat.

In the tutorials page, it said to externalize the settings to something like grails.config.locations = [ "file:Quartz-config.groovy"] in your config.groovy.


Seems like a sensible idea...but for the life of me I couldn't get it to fetch the configs from an externalized source as described here: http://grails.org/doc/latest/guide/single.html#configExternalized

In the end, I gave up and just put my quartz config in Config.groovy. Probably not the ideal place to be but hopefully I'll figure it out and update you folks!

1 comment:

  1. I managed to get the external config file(s) to work by:

    Config.groovy:
    // There exists a JobConfig.groovy in the same folder with Config.groovy
    // Multiple config files are loaded this way.
    def commonConfigs = [
        'Job',
        //...
    ]

    commonConfigs.each { String filenamePart ->
        Class cls = Class.forName("${filenamePart}Config", true, Thread.currentThread().contextClassLoader)
        grails.config.locations << cls

        // for overriding things in individual dev env
        grails.config.locations << "file:${userHome}/${appName}-${filenamePart}Config.groovy"
    }

    ReplyDelete