-
-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for disabled cron expression "-" #216
Comments
Interesting. Yeah, that is not supported. I think I primarily meant that seconds are supported, so I probably should update the doc. Not sure if it is possible to support that scenario just yet. When we add support for pausing/stopping an execution in db-scheduler, this would be a nice addition |
We currently use this workaround, which is okay but not perfect:
|
This is the workaround that I use. The @Configuration
public class ClusteredSchedulerConfiguration {
private static final String DISABLED_CRON_EXPRESSION = "-";
private static final Logger logger = LoggerFactory.getLogger(ClusteredSchedulerConfiguration.class);
@Bean
Task<Void> scheduleTaskInvitationsSender(ScheduledTask taskInvitationsSender,
@Value("${cron.task-invitations-sender}") String schedule) {
return scheduleTask(schedule, taskInvitationsSender);
}
@Bean
Task<Void> scheduleAutocompleteEvents(ScheduledTask autocompleteEventsUpdater,
@Value("${cron.autocomplete-events}") String schedule) {
return scheduleTask(schedule, autocompleteEventsUpdater);
}
private Task<Void> scheduleTask(String cronExpression, ScheduledTask task) {
boolean isTaskDisabled = DISABLED_CRON_EXPRESSION.equals(cronExpression);
if (isTaskDisabled) {
var taskName = task.getTaskName();
logger.warn("The {} scheduled task is disabled in the current environment", taskName);
/*
A workaround for the fact that db-scheduler doesn't support Spring's disabled cron expression
https://github.com/kagkarlsson/db-scheduler/issues/216
Return a once-off task that is never scheduled and does nothing when executed
*/
return Tasks.oneTime(taskName, Void.class).execute((inst, ctx) -> {
});
} else {
Schedule schedule = cron(cronExpression);
return Tasks.recurring(task.getTaskName(), schedule).execute((instance, ctx) -> task.run());
}
}
} |
Hoping this is solved with #286. Does that implementation work for you? |
Tested and it works well for us. |
Excellent, thanks for the feedback! |
Fixed in 11.2 |
@kagkarlsson tested and confirmed it works, thanks very much |
According to the docs, db-scheduler supports
However, a Spring cron expression of "-" means the task will never run, which is useful for disabling a task in a local/test environment.
I tried this expression with db-scheduler, but it caused this exception:
The text was updated successfully, but these errors were encountered: