...

Source file src/github.com/chaos-mesh/chaos-mesh/controllers/utils/recorder/schedule.go

Documentation: github.com/chaos-mesh/chaos-mesh/controllers/utils/recorder

     1  // Copyright 2021 Chaos Mesh Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package recorder
    15  
    16  import (
    17  	"fmt"
    18  	"time"
    19  )
    20  
    21  type MissedSchedule struct {
    22  	MissedRun time.Time
    23  }
    24  
    25  func (m MissedSchedule) Type() string {
    26  	return "Warning"
    27  }
    28  
    29  func (m MissedSchedule) Reason() string {
    30  	return "MissSchedule"
    31  }
    32  
    33  func (m MissedSchedule) Message() string {
    34  	return fmt.Sprintf("Missed scheduled time to start a job: %s", m.MissedRun.Format(time.RFC1123Z))
    35  }
    36  
    37  type ScheduleSpawn struct {
    38  	Name string
    39  }
    40  
    41  func (s ScheduleSpawn) Type() string {
    42  	return "Normal"
    43  }
    44  
    45  func (s ScheduleSpawn) Reason() string {
    46  	return "Spawned"
    47  }
    48  
    49  func (s ScheduleSpawn) Message() string {
    50  	return fmt.Sprintf("Create new object: %s", s.Name)
    51  }
    52  
    53  type ScheduleForbid struct {
    54  	RunningName string
    55  }
    56  
    57  func (s ScheduleForbid) Type() string {
    58  	return "Warning"
    59  }
    60  
    61  func (s ScheduleForbid) Reason() string {
    62  	return "Forbid"
    63  }
    64  
    65  func (s ScheduleForbid) Message() string {
    66  	return fmt.Sprintf("Forbid spawning new job because: %s is still running", s.RunningName)
    67  }
    68  
    69  type ScheduleSkipRemoveHistory struct {
    70  	RunningName string
    71  }
    72  
    73  func (s ScheduleSkipRemoveHistory) Type() string {
    74  	return "Warning"
    75  }
    76  
    77  func (s ScheduleSkipRemoveHistory) Reason() string {
    78  	return "Skip"
    79  }
    80  
    81  func (s ScheduleSkipRemoveHistory) Message() string {
    82  	return fmt.Sprintf("Skip removing history: %s is still running", s.RunningName)
    83  }
    84  
    85  func init() {
    86  	register(MissedSchedule{}, ScheduleSpawn{}, ScheduleForbid{}, ScheduleSkipRemoveHistory{})
    87  }
    88