question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 https://github.com/spring-projects/spring-framework/commit/3a5def047f2aeb8b01d94febdabb52c013c1f676

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
spring-projects-issuescommented, Jan 11, 2019

Juergen Hoeller commented

I’ve implemented this with a simple skip check in processScheduled if the cron value is “-” (the new Scheduled.CRON_DISABLED constant). This seems quite aligned with cron’s symbolic nature. Any issues with that choice from your side?

0reactions
spring-projects-issuescommented, Jan 11, 2019

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Cron scheduler “disable pattern” - Stack Overflow
As of Spring 5.1.0 the @Scheduled annotation can accept "-" as the cron expression to disable the cron trigger. Per the Javadocs:.
Read more >
How to Start, Stop, and Restart Cron Jobs - Airplane.dev
In this post, we'll take an in-depth look at what a cron job is, its uses, and how to start, stop, and restart...
Read more >
Conditionally Enable Scheduled Jobs in Spring - Baeldung
The simplest way to conditionally enable a Spring scheduled job is to use a boolean variable that we check inside the scheduled job....
Read more >
Can I Start/Stop a job based on a parameter?
schedule ('Repeater Upload Contracts', cronExpression, new Repeater_Scheduler_Upload_Contract());. I now have a requirement, to be able to start/ ...
Read more >
Need a way to programatically change or delete a Scheduled ...
I am able to create one easily enough, but once it is made I can only look at the values in the CronTrigger...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found