go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/supervisor/service_history.go (about) 1 /* 2 3 Copyright (c) 2024 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package supervisor 9 10 import "time" 11 12 // Exit is a time and a error associated with a service exiting. 13 type Exit struct { 14 Timestamp time.Time 15 Error error 16 } 17 18 // ServiceHistory is the relevant bits of a service's history. 19 type ServiceHistory struct { 20 StartedAt time.Time 21 Exits []Exit 22 } 23 24 // RecentFailures returns just the last N exits that have an error. 25 func (sh ServiceHistory) RecentFailures() (failures []Exit) { 26 for x := len(sh.Exits) - 1; x >= 0; x-- { 27 if sh.Exits[x].Error == nil { 28 return 29 } 30 failures = append(failures, sh.Exits[x]) 31 } 32 return 33 }