mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-25 09:24:04 +01:00
Fix issue with under maintenance
This commit is contained in:
parent
0d284c2494
commit
428e415616
@ -3,7 +3,6 @@ package maintenance
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -98,7 +97,7 @@ func (c Config) IsUnderMaintenance() bool {
|
|||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
dayWhereMaintenancePeriodWouldStart := now.Add(-c.Duration).Truncate(24 * time.Hour)
|
dayWhereMaintenancePeriodWouldStart := now.Add(-c.Duration).Truncate(24 * time.Hour)
|
||||||
hasMaintenanceEveryDay := len(c.Every) == 0
|
hasMaintenanceEveryDay := len(c.Every) == 0
|
||||||
hasMaintenancePeriodScheduledForThatWeekday := sort.SearchStrings(c.Every, dayWhereMaintenancePeriodWouldStart.Weekday().String()) != len(c.Every)
|
hasMaintenancePeriodScheduledForThatWeekday := c.hasDay(dayWhereMaintenancePeriodWouldStart.Weekday().String())
|
||||||
if !hasMaintenanceEveryDay && !hasMaintenancePeriodScheduledForThatWeekday {
|
if !hasMaintenanceEveryDay && !hasMaintenancePeriodScheduledForThatWeekday {
|
||||||
// The day when the maintenance period would start is not scheduled
|
// The day when the maintenance period would start is not scheduled
|
||||||
// to have any maintenance, so we can just return false.
|
// to have any maintenance, so we can just return false.
|
||||||
@ -109,6 +108,15 @@ func (c Config) IsUnderMaintenance() bool {
|
|||||||
return now.After(startOfMaintenancePeriod) && now.Before(endOfMaintenancePeriod)
|
return now.After(startOfMaintenancePeriod) && now.Before(endOfMaintenancePeriod)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Config) hasDay(day string) bool {
|
||||||
|
for _, d := range c.Every {
|
||||||
|
if d == day {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func hhmmToDuration(s string) (time.Duration, error) {
|
func hhmmToDuration(s string) (time.Duration, error) {
|
||||||
if len(s) != 5 {
|
if len(s) != 5 {
|
||||||
return 0, errInvalidMaintenanceStartFormat
|
return 0, errInvalidMaintenanceStartFormat
|
||||||
|
Loading…
Reference in New Issue
Block a user