Hello,
All my cron are working well except this one with "every x and y minute"
I'm using Spring Boot 2.5.4
I tried this :
@Scheduled(cron = "0 5,10 5-23 * * *", zone = "Europe/Paris")
The cron task is executed every minute, it's like i wrote "0 * 5-23 * * *" So we can use a coma for hours (like I saw in the documentation) but not for minutes ?
The solution I found is to use multiple tasks
@Scheduled(cron = "0 5 5-23 * * *", zone = "Europe/Paris")
@Scheduled(cron = "0 10 5-23 * * *", zone = "Europe/Paris")
It works but I think it will cause issues if the tasks are too long or too close to eachother
Comment From: jaoromi
I used Spring Boot 2.5.4, and test using your setting @Scheduled(cron = "0 5,10 5-23 * * *", zone = "Europe/Paris")
. but It only executed for exactly 5, 10 minutes.
Comment From: rstoyanchev
We have CronExpressionTests. I can write the following for the exact scenario and it passes:
@Test
void specificMinutesAndHours() {
CronExpression expression = CronExpression.parse("0 5,10 5-23 * * *");
LocalDateTime last = LocalDateTime.now().withHour(5).withMinute(1);
LocalDateTime expected = last.withMinute(5).withSecond(0).withNano(0);
LocalDateTime actual = expression.next(last);
assertThat(actual).isNotNull();
assertThat(actual).isEqualTo(expected);
last = LocalDateTime.now().withHour(5).withMinute(5).withSecond(1);
expected = last.withMinute(10).withSecond(0).withNano(0);
actual = expression.next(last);
assertThat(actual).isNotNull();
assertThat(actual).isEqualTo(expected);
last = LocalDateTime.now().withHour(5).withMinute(10).withSecond(1);
expected = last.withHour(6).withMinute(5).withSecond(0).withNano(0);
actual = expression.next(last);
assertThat(actual).isNotNull();
assertThat(actual).isEqualTo(expected);
}
You will need to provide a failing test or sample that demonstrates the issue.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.