NiBE
NiBE

Reputation: 927

How to avoid quartz starting when grail application start

I have a simple application in GRAILS which use Quartz2 plugin. In the job file I have:

static triggers = {
    simple repeatCount: 0 // execute job once in 5 seconds
    cron cronExpression: '0 15 2 * * ?'
}

def execute() {
    if (Environment.current == Environment.PRODUCTION)
        do something...
}

Everything works fine in this case, if it's not in production the trigger is ignored. Now the question is simple, if I start the application in the production the jobs starts as soon as the grails fire up. I wish to avoid the job running asap the app starts,but only when is correctly set in the cronExpression.

Any idea?

UPDATE: At the end I put this line in config.groovy:

environments {
    development {
       grails.logging.jul.usebridge = true
       grails.plugin.quartz2.autoStartup = false
    }
    production {
      grails.logging.jul.usebridge = false
  }  
}

Now it seems not to start at the bootstrap I have to do a couple of test more and I let you know.

thank you

UPDATE2: Ok now the schedule doesn't start at all, I was expecting that it starts but don't execute the jobs scheduled but wait the right time to trigger it. Any help?

thanks a lot

UPDATE3: Sorry but I feel really stupid, adding simple repeatCount:0 fire once at start up, so deleting that it works perfect, sorry again.

Upvotes: 4

Views: 4682

Answers (1)

GeoGriffin
GeoGriffin

Reputation: 1095

By setting up conf\QuartzConfig.groovy, you can control which environments that job sceduling automaically starts. For example:

quartz {
    autoStartup = true
    jdbcStore = false
    waitForJobsToCompleteOnShutdown = true
}

environments {
    development {
        quartz {
            autoStartup = false
        }
    }
}

In your jobs class, you can also set a startDelay on your trigger

static triggers = {
    cron name: 'myTrigger', startDelay: 5000, cronExpression: '0 15 2 * * ?'
}

Upvotes: 5

Related Questions