I'm wondering if there is a way to disable jobs using config.groovy or by some other means. I've seen posts where you can disable plugins via config.groovy, but haven't seen anything about jobs. I'd like to be able to either disable all jobs, or disable each job individually without having to comment them out. Thank you.
Asked
Active
Viewed 2,491 times
3 Answers
7
As the triggers are defined as a static member in a job, you can override these in Config.groovy
. You can also therefore remove the triggers for a particular job in configuration, thereby disabling it:
MyJob.groovy
class MyJob {
static triggers = {
simple name: 'mySimpleTrigger', startDelay: 60000, repeatInterval: 1000
}
def execute() {
// Job code goes here
// This method won't get called using the configuration below
}
}
Config.groovy
MyJob.triggers = {}

Chris Peacock
- 4,107
- 3
- 26
- 24
-
1Thanks for the help. This is by far better than introducing a new variable for every job to check. – John Mercier Apr 14 '15 at 19:00
3
I assume you use Quartz plugin. In this case you can disable it via Config.groovy
quartz {
autoStartup = false
}

vmorarian
- 62
- 1
- 2
1
Something like the following would effectively disable each job (though this is not exactly the same as disabling the Quartz plugin completely):
Config.groovy
MyJob.diabled = true
MyOtherJob.disabled = false
MyJob.groovy
class MyJob {
def grailsApplication
static triggers = {
simple name: 'mySimpleTrigger', startDelay: 60000, repeatInterval: 1000
}
def execute() {
String className = getClass().simpleName
if (grailsApplication.config."$className".disabled) {
return
}
// Job code goes here
}
}
To avoid repeating the code above in each Job class either put in into an abstract base class (or use metaprogramming to achieve the same result without inheritance).

Dónal
- 185,044
- 174
- 569
- 824