maintenance.go
maintenance.go - Overview
-
Overview The
maintenance.go
file defines the structures and functions related to planned maintenance, including validation and schedule management. -
Detailed Documentation
Constants:
ErrMissingName
:errors.New("missing name")
- Error indicating a missing name.ErrMissingSchedule
:errors.New("missing schedule")
- Error indicating a missing schedule.ErrMissingTimezone
:errors.New("missing timezone")
- Error indicating a missing timezone.ErrMissingRepeatType
:errors.New("missing repeat type")
- Error indicating a missing repeat type.ErrMissingDuration
:errors.New("missing duration")
- Error indicating a missing duration.
Type: PlannedMaintenance
- Purpose: Represents a planned maintenance window.
- Fields:
Id
:int64
- Unique identifier.Name
:string
- Name of the maintenance.Description
:string
- Description of the maintenance.Schedule
:*Schedule
- Schedule details.AlertIds
:*AlertIds
- List of alert IDs to be silenced.CreatedAt
:time.Time
- Creation timestamp.CreatedBy
:string
- User who created the maintenance.UpdatedAt
:time.Time
- Last update timestamp.UpdatedBy
:string
- User who last updated the maintenance.Status
:string
- Current status of the maintenance (e.g., active, upcoming, expired).Kind
:string
- Type of maintenance, either "fixed" or "recurring".
Type: AlertIds
- Purpose: Represents a slice of alert IDs.
- Type:
[]string
Method: Scan
- Purpose: Implements the
sql.Scanner
interface to scan a JSON byte array into anAlertIds
slice. - Parameters:
src
:interface{}
- The source value from the database.
- Returns:
error
- An error if unmarshaling fails.
Method: Value
- Purpose: Implements the
driver.Valuer
interface to convert theAlertIds
slice to a JSON byte array. - Returns:
(driver.Value, error)
- The JSON byte array representation and an error if marshaling fails.
Type: Schedule
- Purpose: Represents the schedule for a planned maintenance.
- Fields:
Timezone
:string
- Timezone for the schedule.StartTime
:time.Time
- Start time (optional for recurring schedules).EndTime
:time.Time
- End time (optional for recurring schedules).Recurrence
:*Recurrence
- Recurrence details (optional for fixed schedules).
Method: Scan
- Purpose: Implements the
sql.Scanner
interface to scan a JSON byte array into aSchedule
struct. - Parameters:
src
:interface{}
- The source value from the database.
- Returns:
error
- An error if unmarshaling fails.
Method: Value
- Purpose: Implements the
driver.Valuer
interface to convert theSchedule
struct to a JSON byte array. - Returns:
(driver.Value, error)
- The JSON byte array representation and an error if marshaling fails.
Method: MarshalJSON
- Purpose: Marshals the
Schedule
struct into a JSON byte array, formatting the time fields according to RFC3339. - Returns:
([]byte, error)
- The JSON byte array representation and an error if marshaling fails.
Method: UnmarshalJSON
- Purpose: Unmarshals a JSON byte array into a
Schedule
struct, parsing the time fields from RFC3339 format. - Parameters:
data
:[]byte
- The JSON data to unmarshal.
- Returns:
error
- An error if unmarshaling fails.
Type: RepeatType
- Purpose: Represents the type of recurrence (daily, weekly, monthly).
- Type:
string
- Constants:
RepeatTypeDaily
:"daily"
RepeatTypeWeekly
:"weekly"
RepeatTypeMonthly
:"monthly"
Type: RepeatOn
- Purpose: Represents the day on which a weekly recurrence repeats (e.g., Sunday, Monday).
- Type:
string
- Constants:
RepeatOnSunday
:"sunday"
RepeatOnMonday
:"monday"
RepeatOnTuesday
:"tuesday"
RepeatOnWednesday
:"wednesday"
RepeatOnThursday
:"thursday"
RepeatOnFriday
:"friday"
RepeatOnSaturday
:"saturday"
Map: RepeatOnAllMap
- Purpose: Mapping between
RepeatOn
strings andtime.Weekday
values. - Type:
map[RepeatOn]time.Weekday
Type: Recurrence
- Purpose: Represents the recurrence details for a planned maintenance.
- Fields:
StartTime
:time.Time
- Start time of the recurrence.EndTime
:*time.Time
- End time of the recurrence (optional).Duration
:Duration
- Duration of each occurrence.RepeatType
:RepeatType
- Type of recurrence (daily, weekly, monthly).RepeatOn
:[]RepeatOn
- Days on which the recurrence repeats (for weekly recurrences).
Method: Scan
- Purpose: Implements the
sql.Scanner
interface to scan a JSON byte array into aRecurrence
struct. - Parameters:
src
:interface{}
- The source value from the database.
- Returns:
error
- An error if unmarshaling fails.
Method: Value
- Purpose: Implements the
driver.Valuer
interface to convert theRecurrence
struct to a JSON byte array. - Returns:
(driver.Value, error)
- The JSON byte array representation and an error if marshaling fails.
Method: PlannedMaintenance.shouldSkip
- Purpose: Determines whether a given rule ID should be skipped based on the planned maintenance schedule and current time.
- Parameters:
ruleID
:string
- The ID of the rule.now
:time.Time
- The current time.
- Returns:
bool
- True if the rule should be skipped, false otherwise.
Method: PlannedMaintenance.IsActive
- Purpose: Checks if the maintenance is currently active.
- Parameters:
now
:time.Time
- Current time.
- Returns:
bool
- True if active, false otherwise.
Method: PlannedMaintenance.IsUpcoming
- Purpose: Checks if the maintenance is upcoming.
- Returns:
bool
- True if upcoming, false otherwise.
Method: PlannedMaintenance.IsRecurring
- Purpose: Checks if the maintenance is a recurring one.
- Returns:
bool
- True if recurring, false otherwise.
Method: PlannedMaintenance.Validate
- Purpose: Validates the PlannedMaintenance struct, checking for missing or invalid fields.
- Returns:
error
- An error if validation fails.
Method: PlannedMaintenance.MarshalJSON
- Purpose: Marshals the PlannedMaintenance struct into a JSON byte array, adding computed status and kind fields.
- Returns:
([]byte, error)
- The JSON byte array representation and an error if marshaling fails.
Method: PlannedMaintenance.checkDaily
- Purpose: Checks if the maintenance is active on daily schedule
- Parameters:
currentTime
:time.Time
- The current time.rec
:*Recurrence
- Pointer to the recurrene.loc
:*time.Location
- Pointer to the location.
- Returns:
bool
- True if the rule should be skipped, false otherwise.
Method: PlannedMaintenance.checkWeekly
- Purpose: Checks if the maintenance is active on weekly schedule
- Parameters:
currentTime
:time.Time
- The current time.rec
:*Recurrence
- Pointer to the recurrene.loc
:*time.Location
- Pointer to the location.
- Returns:
bool
- True if the rule should be skipped, false otherwise.
Method: PlannedMaintenance.checkMonthly
- Purpose: Checks if the maintenance is active on monthly schedule
- Parameters:
currentTime
:time.Time
- The current time.rec
:*Recurrence
- Pointer to the recurrene.loc
:*time.Location
- Pointer to the location.
- Returns:
bool
- True if the rule should be skipped, false otherwise.
Include in Getting Started: NO