Search code examples
grailscronquartz-schedulerquartz-core

grails quartz job never gets executed


I have this job:

class MyJob {
    static triggers = {
      cron name:"some job", cronExpression:"0 0 * * * ? *"
    }

    def execute() {
        log.info "job runs"
    }
}

The job should run every hour. I thought that the problem is the cronExpression. That's why I changed it to the expression above. Before I had this expression:

0 0 0/1 1/1 * ? *

But none of the expressions work.

My setup:

I have 10 jobs that run between every 5 minutes to once per month. Every job seems to run except this one...

My questions:

  1. Why is the job not executed?
  2. Is there a max_jobs parameter that is responsible for this?

Solution

    1. Try without year:

      static triggers = {
          cron name: 'myTrigger', cronExpression: "0 0 0-23 * * ?"
      }
      
    2. You can control it f.e. by predicting time of execution and preparing proper expression (it triggers only twice a month; on first day of month at 1.00 and 2.00 am):

      static triggers = {
          cron name: 'myTrigger', cronExpression: "0 0 1-2 1 * ?"
      }
      

      Read more about different types of triggers:

    Currently plugin supports three types of triggers:

    • simple — executes once per defined interval (ex. “every 10 seconds”);
    • cron — executes job with cron expression (ex. “at 8:00am every Monday through Friday”);
    • custom — your implementation of Trigger interface.

    Remember also about:

    The triggers name property must be unique across all triggers in the application.

    By default, jobs will not be executed when running under the test environment.

    More examples you can find here.