Skip to content
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

Unexpected error while executing OnStartup tasks - Unsupported unit: Years #361

Open
kamil-j opened this issue Feb 17, 2023 · 5 comments
Open
Labels

Comments

@kamil-j
Copy link

kamil-j commented Feb 17, 2023

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

@kagkarlsson
Copy link
Owner

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

@kamil-j
Copy link
Author

kamil-j commented Feb 17, 2023

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)

@kagkarlsson
Copy link
Owner

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

@kamil-j
Copy link
Author

kamil-j commented Feb 18, 2023

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

@kagkarlsson
Copy link
Owner

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

kagkarlsson added a commit that referenced this issue Dec 6, 2023
…fail. (#435)

Introduce an `Instant.NEVER` that represents future execution-time that
will never run, and use this for cron-patterns with no next
execution-time.

## Fixes
* #361 


## Reminders
- [ ] Added/ran automated tests
- [x] Update README and/or examples
- [x] Ran `mvn spotless:apply`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants