kagkarlsson / db-scheduler

Persistent cluster-friendly scheduler for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected error while executing OnStartup tasks - Unsupported unit: Years

kamil-j opened this issue · comments

Hello,

I am getting the following exception during app startup:

2023-02-17 14:22:15.490 ERROR [hrs,,] 15732 --- [ main] c.g.kagkarlsson.scheduler.Scheduler : Unexpected error while executing OnStartup tasks. Continuing. java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Years at java.base/java.time.Instant.plus(Instant.java:862) at com.github.kagkarlsson.scheduler.task.schedule.CronSchedule.getNextExecutionTime(CronSchedule.java:69) at com.github.kagkarlsson.scheduler.task.schedule.Schedule.getInitialExecutionTime(Schedule.java:30)

Java Instant does not support adding YEARS and would be good to replace it with e.g. a high amount of days?

This cron expression can be used to reproduce issue: 0 0 0 29 2 MON#1

Context/Explanation:
My requirement is to never run a recurring task automatically (at this point but it can change in the future and it should be possible without development by changing cron expression in props) but only on request. To run task on-request I am calling 'reschedule' method in this way: schedulerClient.reschedule(taskInstanceId, Instant.now())
Unfortunately, I can't use '-' as a cron expression to disable automatic execution as in that case it is not possible to run task on request (looks like task is not registered at the app startup?). So I am looking for an alternative. I could use e.g. 0 0 0 29 2 MON but it is not ideal as task will be run on 29 Feb 2044 but should never :) Ideally for me, would be good to have possibility to turn off auto-execution (with '-' as cron) and still allow execution on demand - or at least fix above issue and support passing crons like 0 0 0 29 2 MON#1

It sounds a bit like a one-time task if it should only run on request?

I just edited to explain it. In the future it may change and should run according to the provided schedule :) It is not the only case, we have many tasks in the system with pretty the same requirement - for some time they should run according to the schedule but at some point in time it may be needed to stop automatic execution and run them only on request e.g. for few weeks/months (but we should avoid additional development)

How would you control the when the recurring tasks are stopped and when they are resumed? Redeploy when different schedule?

Yes, it's just an update to props in a config server and app restart node by node.

I think you should be able to accomplish something like this with a combination of a recurring task and a one-time task using a similar ExecutionHandler