1

I have a cron job in my spring boot application which runs periodically. On enabling job, Automatically jobs are getting triggered and it is working as expected in Windows tomcat server

But when the same code is deployed into Linux Docker environment. Jobs are not getting triggered at the scheduled time. I verified few links below. But it didn't solve my problem. Spring Boot Scheduled task not working on docker container

What is the right approach to handle this?

TestJobScheduler.class:
-------------------------
@Configuration
@EnableScheduling
public class TestJobScheduler {

    @Value("${test.job.enabled}")
    private boolean isTestJobEnabled;
    
    @Scheduled(cron = "${test.cron.expression}")
    public void testSchedulerJob() {
        if(isTestJobEnabled) {
            //Do your work
        }
    }
}

application.properties:
------------------------
test.job.enabled=true
test.cron.expression=0 0 6 ? * 3,5
Thej
  • 191
  • 1
  • 6
  • 23

2 Answers2

1

I had this problem and it was because the docker container was automatically on UTC time zone, try running "date" in the container and seeing what time it is.

To change time zone using ubuntu as the base image, add to the dockerfile:

RUN apt-get update && apt-get -y install tzdata
ENV TZ="insert-time-zone" //Example: America/Chicago

Check out this question for more information.

0

Add to your Dockerfile:

RUN apt-get update && apt-get -y install tzdata
ENV TZ="America/Araguaina"
RUN date
meher
  • 61
  • 1
  • 9