croner
croner copied to clipboard
[Bug] `interval` setting does seem to ignore `startAt`
Describe the bug Hi, first thanks a ton for the library. We have been (ab)using it a lot.
I think we have come across what I think is a bug in the implementation of https://github.com/Hexagon/croner/issues/63:
If startAt
is in the past, interval
does not calculate starting from startAt
but is skippped instead (We think).
To Reproduce Steps to reproduce the behavior:
- enter
startAt
and an absurdly largeinterval
(to make what I think is a bug more obvious ^^) - Run code
https://jsfiddle.net/ak85Lwrv/4/
Expected behavior
I would expect that the first execution of the cronjob is not "now" and then the interval
comes into play, but rather that this respects startAt
.
System:
- OS: Manjraro/Linux
- Runtime Chrome/JSfiddle
- Version 124.0.6367.91
Additional context This issue is the outcome of the investigation of @buzzinJohnnyBoi in https://github.com/louislam/uptime-kuma/pull/4738
Oh! Will have a look at this as soon as possible. Thanks for a great bug report!
Hello, @Hexagon, I gave finding the bug a shot, and I think I have fixed it.
In the /src/croner.js
file (_next
function), I just added a check !prev && options.startAt && options.interval
, then calculate when prev (previous run) should have been. I have tested this with multiple different values, and it gets the correct value each time.
All tests and linters pass, and I have run npm run build
and the tests for dist
pass as well.
I also added a test in /src/suites/options.cjs
with the startAt in the past and the excepted date in the future.
Is it OK if I create a PR for this issue?
My Commit
@buzzinJohnnyBoi Awesome, send the PR 👍
I sent the PR, wasn't sure if you wanted me to include the changes after running npm run build
, so I looked at some of your previous PRs and it looks like you do that sometimes, so I included them :)
@buzzinJohnnyBoi's fix available to test through npm i [email protected]
Closing as https://github.com/Hexagon/croner/pull/248 was merged ^^ Thanks everyone ❤️
An additional fix by @buzzinJohnnyBoi released through prerelease 8.0.3-dev.1