This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.go
82 lines (62 loc) · 1.69 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package task
import (
"reflect"
"time"
boshuifmt "github.com/cloudfoundry/bosh-cli/ui/fmt"
)
const (
EventTypeDeprecation = "deprecation"
EventStateStarted = "started"
EventStateFinished = "finished"
EventStateFailed = "failed"
EventStateInProgress = "in_progress"
)
type Event struct {
UnixTime int64 `json:"time"` // e.g 1451020321
Type string // e.g. "deprecation"
Message string
State string // e.g. "started"
Stage string // e.g. "Preparing deployment"
Task string // e.g. "Binding deployment"
Tags []string // e.g. ["api"]
Total int // e.g. 0
Index int // e.g. 0
Progress int // e.g. 0
Data EventData
Error *EventError
StartEvent *Event
}
type EventData struct {
Error string // e.g. "'api2/2' is not running after update"
}
type EventError struct {
Code int // e.g. 100
Message string // e.g. "Bosh::Director::Lock::TimeoutError"
}
func (e Event) IsSame(other Event) bool {
return e.IsSameGroup(other) && e.Task == other.Task
}
func (e Event) IsSameGroup(other Event) bool {
return len(e.Stage) != 0 && e.Stage == other.Stage && reflect.DeepEqual(e.Tags, other.Tags)
}
func (e Event) Time() time.Time {
return time.Unix(e.UnixTime, 0).UTC()
}
func (e Event) TimeAsStr() string {
return e.Time().Format(boshuifmt.TimeFullFmt)
}
func (e Event) TimeAsHoursStr() string {
return e.Time().Format(boshuifmt.TimeHoursFmt)
}
func (e Event) DurationAsStr(later Event) string {
return boshuifmt.Duration(later.Time().Sub(e.Time()))
}
func (e Event) DurationSinceStartAsStr() string {
if e.StartEvent != nil {
return e.StartEvent.DurationAsStr(e)
}
return ""
}
func (e Event) IsWorthKeeping() bool {
return e.State != EventStateInProgress
}