grails / grails-quartz

This project provides integration of the Quartz scheduling framework into the Grails Framework
http://grails.org/plugin/quartz
Apache License 2.0
76 stars 90 forks source link

Grails Quartz Plugin

Maven Central Java CI

Documentation

Latest documentation and snapshots are available.

Branches

Branch Grails Version
1.x 2
2.0.x 3-5
3.0.x 6

Using

Quick start

To start using Quartz plugin just simply add implementation 'org.grails.plugins:quartz:{version}' in your build.gradle.

[!NOTE] 2.0.13 for Grails 3.3.*\ Properties changed to static from def.\ For example: def concurrent will be now static concurrent.

Scheduling Jobs

To create a new job run the grails create-job command and enter the name of the job. Grails will create a new job and place it in the grails-app/jobs directory:

package com.mycompany.myapp

class MyJob {

    static triggers = {
        simple repeatInterval: 1000
    }

    void execute() {
        print "Job run!"
    }
}

The above example will call the execute() method every second.

Scheduling configuration syntax

Currently, plugin supports three types of triggers:

Multiple triggers per job are allowed.

class MyJob {

    static triggers = {
        simple name: 'simpleTrigger', startDelay: 10000, repeatInterval: 30000, repeatCount: 10
        cron name: 'cronTrigger', startDelay: 10000, cronExpression: '0/6 * 15 * * ?'
        custom name: 'customTrigger', triggerClass: MyTriggerClass, myParam: myValue, myAnotherParam: myAnotherValue
    }

    void execute() {
        println "Job run!"
    }
}

With this configuration, job will be executed 11 times with 30 seconds interval with first run in 10 seconds after scheduler startup (simple trigger), also it'll be executed each 6 second during 15th hour (15:00:00, 15:00:06, 15:00:12, ... — this configured by cron trigger) and also it'll be executed each time your custom trigger will fire.

Three kinds of triggers are supported with the following parameters. The name field must be unique:

Configuration plugin syntax

You can add the following properties to control persistence or not persistence: