Skip to content

Make it possible to disable Scheduled job via cron expression [SPR-16858] #21397

@spring-projects-issues

Description

@spring-projects-issues

Nikolay 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 3a5def0

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions