Comments (3)
@greenlaw110 thank you for reporting this!
Could you please provide the cron expression you are using to execute the code, and perhaps a test that reproduces the issue? Thank you in advance!
from cron-utils.
Actually any cron expression lead to the same result. That's because the pattern I've used to applying cron-util. As you see schedule
method is executed right at the time cron task should invoke (actually just invoked), thus you want to get the timeToNextExecution
exactly when it's due to execution, the library returns 0, which is the timeToCurrentExecution
. I end up with something like following to workaround the issue:
void schedule(AppJobManager manager, _Job job) {
DateTime now = DateTime.now();
ExecutionTime executionTime = ExecutionTime.forCron(cron);
Duration nextExecution = executionTime.timeToNextExecution(now.withDurationAdded(1, 1));
long seconds = nextExecution.getStandardSeconds();
int times = 1;
while (seconds == 0) {
nextExecution = executionTime.timeToNextExecution(now.withDurationAdded(1, times++));
seconds = nextExecution.getStandardSeconds();
}
manager.executor().schedule(job, seconds, TimeUnit.SECONDS);
}
from cron-utils.
@greenlaw110 I tried to reproduce the issue, but I do not get the issue.
If you have too short intervals, then you will get zero seconds; depending on the cron expression you consider. But if you invoke nextExecution.getMillis(), you may notice that time to next execution decreases accurately.
Also looking at different cron setups, returns accurate results, where Duration interval to next execution is not zero seconds. Example: using the following code, you get a non-zero value most of time.
ExecutionTime executionTime = ExecutionTime.forCron(quartzCronParser.parse("5 * * * * *"));
DateTime now = DateTime.now();
Duration nextExecution = executionTime.timeToNextExecution(now);
long seconds = nextExecution.getStandardSeconds();
Please validate and let us know the result. Will be happy to help on it.
from cron-utils.
Related Issues (20)
- Unix Cron to Quartz Cron Expression Converter
- Is there a chance to have CronMapper from QUARTZ to SPRING53 ? HOT 2
- Can we have a release? HOT 5
- Integrating cron-utils into OSS-Fuzz
- DEBUG com.cronutils.model.time.generator.AndFieldValueGenerator - Catched expected exception while generating candidates com.cronutils.model.time.generator.NoSuchValueException: null HOT 2
- Cron Field endRange may not be correct HOT 1
- Cannot map day of week (5#1) HOT 2
- Validation error while generate cron string using cronBuilder HOT 1
- Support random time intervals HOT 2
- How to create a cron expression for every N hours between time X to time Y
- ExecitionTime not working when using QUARTZ and time is beyond 2100.
- LastExecution comes up with incorrect day when reference month is shorter than month of last execution HOT 1
- 每月中多个天数,其中月末未执行
- Describe and describeHHmmss methods with configurable 12/24 hours format
- different execution time behaviour for sec or min lowest field HOT 2
- CronValidator should support jakarta.validation
- The description of the cron expression in Chinese is not very user-friendly
- how to compute the number of executions between two days? HOT 1
- ExecutionTime.nextExecution/timeToNextExecution issue on Daylight Saving Time HOT 1
- The URL has been changed to 'cron-parser.com', and the readme and link have not changed. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cron-utils.