...

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  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  
    16  package recorder
    17  
    18  import (
    19  	"fmt"
    20  	"time"
    21  )
    22  
    23  type MissedSchedule struct {
    24  	MissedRun time.Time
    25  }
    26  
    27  func (m MissedSchedule) Type() string {
    28  	return "Warning"
    29  }
    30  
    31  func (m MissedSchedule) Reason() string {
    32  	return "MissSchedule"
    33  }
    34  
    35  func (m MissedSchedule) Message() string {
    36  	return fmt.Sprintf("Missed scheduled time to start a job: %s", m.MissedRun.Format(time.RFC1123Z))
    37  }
    38  
    39  type ScheduleSpawn struct {
    40  	Name string
    41  }
    42  
    43  func (s ScheduleSpawn) Type() string {
    44  	return "Normal"
    45  }
    46  
    47  func (s ScheduleSpawn) Reason() string {
    48  	return "Spawned"
    49  }
    50  
    51  func (s ScheduleSpawn) Message() string {
    52  	return fmt.Sprintf("Create new object: %s", s.Name)
    53  }
    54  
    55  type ScheduleForbid struct {
    56  	RunningName string
    57  }
    58  
    59  func (s ScheduleForbid) Type() string {
    60  	return "Warning"
    61  }
    62  
    63  func (s ScheduleForbid) Reason() string {
    64  	return "Forbid"
    65  }
    66  
    67  func (s ScheduleForbid) Message() string {
    68  	return fmt.Sprintf("Forbid spawning new job because: %s is still running", s.RunningName)
    69  }
    70  
    71  type ScheduleSkipRemoveHistory struct {
    72  	RunningName string
    73  }
    74  
    75  func (s ScheduleSkipRemoveHistory) Type() string {
    76  	return "Warning"
    77  }
    78  
    79  func (s ScheduleSkipRemoveHistory) Reason() string {
    80  	return "Skip"
    81  }
    82  
    83  func (s ScheduleSkipRemoveHistory) Message() string {
    84  	return fmt.Sprintf("Skip removing history: %s is still running", s.RunningName)
    85  }
    86  
    87  func init() {
    88  	register(MissedSchedule{}, ScheduleSpawn{}, ScheduleForbid{}, ScheduleSkipRemoveHistory{})
    89  }
    90