Reputation: 739
I am new to use Quartz plugin in Grails and want to run simple application. I used the following codes (form quartz plugin docs) but it only runs once. Any Idea? Should I setup anything?
Thanks
class MyJob {
static triggers = { simple name: 'mySimpleTrigger', startDelay: 60000, repeatInterval: 1000 }
def group = "MyGroup"
def execute(){
println "Running Job!"
}
}
Upvotes: 1
Views: 2780
Reputation: 119
You can define a cron inside your triggers in order to configure WHEN your job will be executed:
static triggers = {
cron name: 'mySimpleCron', cronExpression: "0 30 15 * * ?"
}
This will run your job every day at 15:30:00.
Another examples:
1.Fire every minute starting at 2pm and ending at 2:05pm, every day:
cronExpression: "0 0-5 14 * * ?"
2.Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday:
cronExpression: "0 15 10 ? * MON-FRI"
The sintax of the 7 terms expression is:
* * * * * * *
| | | | | | |_ Year [optional]
| | | | | |_ Day of Week, 1-7 or SUN-SAT, ?
| | | | |_ Month, 1-12 or JAN-DEC
| | | |_ Day of Month, 1-31, ?
| | |_ Hour [0-23]
| |_ Minute [0-59]
|_ Second [0-59]
It's easier to define job execution behavior on this way and you'll have more options to configure just by changing your expression and not the entire code.
More information in these links:
Quartz plugin for Grails - Reference Documentation
Upvotes: 0
Reputation: 739
I added the "new Date()" to println and it now works!
class MyJob {
static triggers = { simple name: 'mySimpleTrigger', startDelay: 60000, repeatInterval: 1000 , repeatCount:-1}
def group = "MyGroup"
def execute(){
println "Running Job!"+new Date()
}
}
It seems to me that the quartz makes some optimization, when the state of job is constant it runs it once!
Upvotes: 1
Reputation: 1376
If you want to run job several times then specify repeatCount in simple trigger definition:
repeatCount — trigger will fire job execution (1 + repeatCount) times and stop after that (specify 0 here to have one-shot job or -1 to repeat job executions indefinitely)
Upvotes: 0