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.

Scheduled task with cron not working as expected

See original GitHub issue

Hello. I have a simple Spring Boot application in which I just included the spring-boot-admin-starter-client (version 1.5.2). Everything works fine except for the scheduled method detailed below:

@Service
public class SomeService {

    @Scheduled(cron = "${cron.task.say.hello}")
    public void someMethod() {
        System.out.println("Hello world!");
    }

}

Being cron.task.say.hello: "* * * * * MON-FRI" in the application.yml file.

As you probably noticed it should print Hello world! every second but it doesn’t work. It prints the message every different periods of time. Sometimes it takes 30 seconds, sometimes 20, it varies.

The application´s entry point is below:

@EnableAsync
@EnableScheduling
@SpringBootApplication
public class SchedulerStarter {

    public static void main(String[] args) throws IOException {
        SpringApplication.run(SchedulerStarter.class, args);
    }

}

Removing spring-boot-admin-starter-client and then using spring-boot-starter works as expected.

Not sure if this is a bug or maybe I’m missing a piece of the puzzle.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

4reactions
joshistecommented, Jun 28, 2017

So basically it’s always a good idea to configure a TaskScheduler when using @EnableSchduling… Your TaskScheduler is picked up because of the name…

From the Spring code:

More than one TaskScheduler bean exists within the context, and none is named 'taskScheduler'. Mark one of them as primary or name it 'taskScheduler' (possibly as an alias); or implement the SchedulingConfigurer interface and call ScheduledTaskRegistrar#setScheduler explicitly within the configureTasks() callback

Since the scheduler provided by the SBA client is very similiar to the default one from @EnableScheduling and doesn’t interfere when you are providing a custom one, I tend to not fix this issue.

0reactions
damianfanarocommented, Jun 28, 2017

I agree. This wasn’t an issue of SBA client just lack of knowledge of Spring Scheduling from my side.

Thanks for the feedback!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top Reasons Your Cron Job Isn't Running - Airplane.dev
Top reasons your cron job isn't running · 1. Schedule errors · 2. Environmental incompatibilities · 3. Depleted resources · 4. Overlapping jobs....
Read more >
Why is my crontab not working, and how can I troubleshoot it?
Check that cron is running ... If cron isn't running then your commands won't be scheduled ... ... There may be other methods;...
Read more >
Cron job troubleshooting guide - Cronitor
What to do if your cron job doesn't run when expected · Validate your job schedule. Once you have found your job, verify...
Read more >
Cron job not working as expected configured with Quartz ...
First scheduler which runs every 5 minute forever works well without any problem. ... I wondered why second expression get stops sometimes. cron...
Read more >
Why crontab scripts are not working? - Ask Ubuntu
cron ignores PATH from that file, so runnning somecommand from your script will fail when run with cron, but work when run in...
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