vitess.io/vitess@v0.16.2/go/vt/vtorc/inst/downtime.go (about) 1 /* 2 Copyright 2017 Shlomi Noach, GitHub Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package inst 18 19 import ( 20 "time" 21 ) 22 23 type Downtime struct { 24 Key *InstanceKey 25 Owner string 26 Reason string 27 Duration time.Duration 28 BeginsAt time.Time 29 EndsAt time.Time 30 BeginsAtString string 31 EndsAtString string 32 } 33 34 func NewDowntime(instanceKey *InstanceKey, owner string, reason string, duration time.Duration) *Downtime { 35 downtime := &Downtime{ 36 Key: instanceKey, 37 Owner: owner, 38 Reason: reason, 39 Duration: duration, 40 BeginsAt: time.Now(), 41 } 42 downtime.EndsAt = downtime.BeginsAt.Add(downtime.Duration) 43 return downtime 44 } 45 46 func (downtime *Downtime) Ended() bool { 47 return downtime.EndsAt.Before(time.Now()) 48 } 49 50 func (downtime *Downtime) EndsIn() time.Duration { 51 return time.Until(downtime.EndsAt) 52 }