Make it possible to disable Scheduled job via cron expression [SPR-16858]
See original GitHub issueNikolay Bogdanov opened SPR-16858 and commented
To disable a spring job which uses cron expression you need at least 2 properties:
...
@Value("${jobs.name.enable}")
private boolean jobEnable;
@Scheduled(cron = "0 0 0 1 * ?")
public void execute() \{
if(jobEnable){
//JOB HERE
}
}
...
}
But there is no way to configure it to don’t start any execution at all, but its relatively valuable feature (you can google it, but here is an example https://stackoverflow.com/questions/13835221/quartz-cron-expression-that-will-never-execute)
So the idea of this issue is to enable support for some “never” value for cron expression which will prevent this job from execution forever, so you can use only 1 parameter to configure your job. Example:
@Scheduled(cron = "never")
The exact value to disable a job is negotiable.
Affects: 5.0.6
Referenced from: commits https://github.com/spring-projects/spring-framework/commit/3a5def047f2aeb8b01d94febdabb52c013c1f676
Issue Analytics
- State:
- Created 5 years ago
- Comments:13
Juergen Hoeller commented
I’ve implemented this with a simple skip check in
processScheduled
if the cron value is “-” (the newScheduled.CRON_DISABLED
constant). This seems quite aligned with cron’s symbolic nature. Any issues with that choice from your side?Nikolay Bogdanov commented
Nice, so paragraph 2 is very similar to the original description of the ticket, right? Juergen Hoeller do you need some help here to resolve it?