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

Updated croner to 8.1.0 and fixed "recurring-interval" type maintenance #4939

Merged
merged 8 commits into from
Jul 15, 2024

Conversation

buzzinJohnnyBoi
Copy link
Contributor

@buzzinJohnnyBoi buzzinJohnnyBoi commented Jul 13, 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

Fixes #4634
Possibly #4930

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.

@CommanderStorm CommanderStorm added area:maintenance related to the maintenance mode pr:needs review this PR needs a review by maintainers or other community members labels Jul 13, 2024
Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good to me.
Thanks for the work ❤️
I have left a question below

@@ -253,6 +253,10 @@ class Maintenance extends BeanModel {
duration = this.duration * 1000;
}

if (duration === undefined && this.strategy === "recurring-interval") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need a bit of help understanding the if-clause you added 😅:
Is this not already covered by the if or else branch above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @CommanderStorm, so above is an if - else if - else, and the else if is when this.end_date is set, and it calculates if this.end_date will be before the end of the interval. If it is not, then this.duration is left undefined.
I guess my solution is not the best one, I was not sure if it was left undefined for some other purpose, but if it is not, then I guess the else if should look something like this:

else if (this.end_date) {
    let d = dayjs(this.end_date).diff(dayjs(), "second");
    if (d < this.duration) {
        duration = d * 1000;
    }
    else {
        duration = this.duration * 1000;
    }
}

Let me know if you want me to make this change.

Copy link
Collaborator

@CommanderStorm CommanderStorm Jul 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is better.
duration is never explicitly checked for undefined => I think it being undefined is a bug ^^

While you are at it, I think that while if/... clause would be way better if extracted into a function this.duration = this.inferDuration()
That way the controll flow is not as confusing in the future..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    inferDuration(customDuration) {
        // Check if duration is still in the window. If not, use the duration from the current time to the end of the window
        if (customDuration > 0) {
            return customDuration;
        } else if (this.end_date) {
            let d = dayjs(this.end_date).diff(dayjs(), "second");
            if (d < this.duration) {
                return d * 1000;
            }
        }
        return this.duration * 1000;
    }

Code here
Lmk if this is good.

server/model/maintenance.js Show resolved Hide resolved
server/model/maintenance.js Outdated Show resolved Hide resolved
@CommanderStorm CommanderStorm added question Further information is requested and removed pr:needs review this PR needs a review by maintainers or other community members labels Jul 13, 2024
@CommanderStorm CommanderStorm added this to the 2.0.0 milestone Jul 13, 2024
Co-authored-by: Frank Elsinga <frank@elsinga.de>
package.json Outdated Show resolved Hide resolved
package-lock.json Outdated Show resolved Hide resolved
@CommanderStorm
Copy link
Collaborator

Thanks for the fix! 🎉

Note

This PR is part of the v2.0 merge window => see #4500 for the bugs that need to be addressed before we can ship this release ^^

All changes in this PR are small and uncontroversial ⇒ merging with junior maintainer approval

@CommanderStorm CommanderStorm merged commit ba448c7 into louislam:master Jul 15, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:maintenance related to the maintenance mode question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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