greenPadawan
greenPadawan

Reputation: 1571

Quartz scheduler incorrect schedule time

I have a spring boot application in which I am trying to schedule a job using quartz scheduler to run daily at a specific time of the day. The following is my code to build the trigger.

DailyTimeIntervalScheduleBuilder scheduleBuilder = DailyTimeIntervalScheduleBuilder
.dailyTimeIntervalSchedule()
.startingDailyAt(TimeOfDay.hourAndMinuteFromDate(activeStartTime))
.endingDailyAfterCount(1)
.withMisfireHandlingInstructionFireAndProceed();

MutableTrigger trigger = scheduleBuilder.build();

The problem I am facing is that the job is scheduled but starting from the next day. So for instance, if I schedule the job for May 22 16:45, then the first fire time for the job is set to May 23 16:45.

I have tried using the builder with withIntervalInHours(24) instead of endingDailyAfterCount(1), but the result is the same.

I am not sure what seems to be the problem.

Note: This behavior is the same regardless of when I schedule my job, i.e., it doesn't matter if I execute this code before or after 16:45, the job is always scheduled for the next day

I am using spring boot version 1.5.10 and spring-boot-starter-quartz version 2.2.5.RELEASE

Upvotes: 4

Views: 1212

Answers (1)

TARUN KUMAR DAS
TARUN KUMAR DAS

Reputation: 11

Can you try below code

CalendarIntervalScheduleBuilder schedule = CalendarIntervalScheduleBuilder
                .calendarIntervalSchedule()
                .inTimeZone(TimeZone.getDefault())
                .withIntervalInDays((int) 1)
                .withMisfireHandlingInstructionFireAndProceed();

Trigger trigger = TriggerBuilder
                .newTrigger()
                .startAt(startDateTime)
                .withSchedule(schedule).build();

For the field startDateTime please use current Date time. if you want to start from May 22 16:45 then create the Date object accordingly.

And set the timezone also, or it will pick default system's timezone.

Upvotes: 1

Related Questions