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

Update Cron calculation for recurring interval maintenance #4738

Closed
wants to merge 0 commits into from

Conversation

buzzinJohnnyBoi
Copy link

@buzzinJohnnyBoi buzzinJohnnyBoi commented May 4, 2024

⚠️⚠️⚠️ Since we do not accept all types of pull requests and do not want to waste your time. Please be sure that you have read pull request rules:
https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md#can-i-create-a-pull-request-for-uptime-kuma

Tick the checkbox if you understand [x]:

  • I have read and understand the pull request rules.

Description

I fixed the recurring interval strategy for the Schedule Maintenance section on Uptime Kuma on the server-side.
Since the node.js croner lib does not seem to support doing intervals every x number of days starting from date y, the code re-calculates the next run date every time the Maintenance task ends or the Uptime Kuma server is reset.

Fixes #4634

Type of change

Please delete any options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the style guidelines of this project
  • I ran ESLint and other linters for modified files
  • I have performed a self-review of my own code and tested it
  • I have commented my code, particularly in hard-to-understand areas (including JSDoc for methods)
  • My changes generates no new warnings
  • My code needed automated testing. I have added them (this is optional task)

Screenshots (if any)

Please do not use any external image service. Instead, just paste in or drag and drop the image here, and it will be uploaded automatically.

@buzzinJohnnyBoi
Copy link
Author

I was not able to find a way for the croner lib to run a task on an interval starting from a specific date.
Instead, I calculate the next time the task will run every time the task finishes or the server resets.

@CommanderStorm
Copy link
Collaborator

I was not able to find a way for the croner lib to run a task on an interval starting from a specific date.

Seems like this can be done via using the interval option in connection with the startFrom.

Screenshot from 2024-05-04 15-37-54

Tested via https://jsfiddle.net/6epcL432/1/

@buzzinJohnnyBoi
Copy link
Author

buzzinJohnnyBoi commented May 4, 2024

@CommanderStorm, I tried that first. But, there are 3 problems with that:

  1. If startAt is in the past, say May 01, then it simply runs the next time it can no matter the interval. If you set the interval in your example to 7 days and the start date as May 1st, then it says it will run on May 4th, (today).
  2. If the server is reset, then it will run the next possible date (either the current or next day) if the startAt is in the past.
  3. (The biggest problem): While saving the interval, if (start Maintenance < now < end Maintenance), then it thinks that the next time it will run is the next day. While you can calculate that the interval should run starting from the next second after it is saved, then the interval will not be correct for future runs. I hope that makes sense, because that is the main reason I was not able to do it that way.
    While it would be possible to do it this way (I tired to make it work for 2 weeks) the solution that I have made works better than anything I could come up using the interval. But maybe I was just not doing it right :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked-upstream upstream (i.e. a dependency we depend on will have to do this work)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Recuring Interval Maintenances display wrong dates in the maintenance list
2 participants