-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Recuring Interval Maintenances display wrong dates in the maintenance list #4634
Comments
Hello, is anyone currently working on this issue? If not, then I would like to try my hand at it. |
Nobody is currently working on this to my knowledge ^^ |
I have made a little bit of progress, I was able to reproduce the error and have isolated it to this line of code: uptime-kuma/server/model/maintenance.js Line 300 in 05606c6
If the interval is My question is, what exactly is the |
Not quite. Said variable comes from here: uptime-kuma/server/model/maintenance.js Lines 266 to 268 in 05606c6
To your question:
Sadly, croners docs is not great, but hey.. The duration is initialised here: uptime-kuma/server/model/maintenance.js Lines 390 to 436 in 05606c6
|
Thank you for that info, @CommanderStorm, I think I can solve the issue now, here is my approach: import { Cron } from "croner";
const intervalInDays = 6;
let startDate = new Date('2024-04-14T07:00:00Z');
const hour = startDate.getUTCHours();
const minute = startDate.getUTCMinutes();
const cronString = `${minute} ${hour} * * *`;
const task = () => {
console.log("Running task");
};
const now = new Date();
if (startDate < now) {
const differenceInDays = Math.ceil((now - startDate) / (1000 * 60 * 60 * 24));
const numberIntervalsSinceStartDate = Math.ceil(differenceInDays / intervalInDays);
startDate.setDate(startDate.getDate() + numberIntervalsSinceStartDate * intervalInDays);
}
console.log(`This will run every ${intervalInDays} days, starting from ${startDate}`);
const job = new Cron(cronString, { interval: intervalInDays * 24 * 60 * 60, startAt: startDate.toISOString() });
job.schedule(task);
console.log(job.nextRuns(5)); |
Could you provide a PR instead? Revieingg what has to be changed is more error prown than nessesary via comments.. |
Hi, @CommanderStorm, the PR should be ready for review. I did not use the strategy described above, instead I had to re-calculate the Cron every time the maintenance task is run. While it is not optimal because code needs to be added for only that strategy, it works for every use case. |
I fixed the |
So, croner is now at version 8.1.0, which includes the changes with interval, hopefully allowing me to resolve this issue :) |
📑 I have found these related issues/pull requests
NONE
🛡️ Security Policy
Description
Trying to add a Recuring Interval Maintenance and it seems that it gets the wrong dates.
E.g. trying to add this maintenance on
04/07/2024
It shows wrong data here.
👟 Reproduction steps
Add a recuring interval maintenance e.g. running once every 7 days starting from a specific date and after it ads it, it displays the wrong data in the Maintenance list.
👀 Expected behavior
It should show the right date which we have added in the first step.
😓 Actual Behavior
It shows the wrong date.
🐻 Uptime-Kuma Version
1.23.11
💻 Operating System and Arch
Ubuntu 22.04 LTS
🌐 Browser
Google Chrome Version 123.0.6312.86 (Official Build) (64-bit)
🖥️ Deployment Environment
📝 Relevant log output
No response
The text was updated successfully, but these errors were encountered: