-
Notifications
You must be signed in to change notification settings - Fork 23
/
events.go
81 lines (65 loc) · 2.45 KB
/
events.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
package models
import "fmt"
type EventType string
const (
EventTypeError EventType = "error"
EventTypeInfo EventType = "info"
)
type EventStage string
const (
EventStageDeployingDependencies EventStage = "deploying dependencies"
EventStageDeployingServices EventStage = "deploying services"
EventStageDeploymentSuccess EventStage = "deployment success"
EventStageDeploymentFailed EventStage = "deployment failed"
EventStageRollback EventStage = "rollback deployment"
EventStageUpdatingEndpoint EventStage = "updating endpoint"
EventStageUndeployingPreviousVersion EventStage = "undeploying previous version"
EventStageDeletingDependencies EventStage = "deleting dependencies"
EventStageUndeployingServices EventStage = "undeploying services"
EventStageDeletingEndpoint EventStage = "deleting endpoint"
EventStageUndeploymentFailed EventStage = "undeployment failed"
EventStageUndeploymentSuccess EventStage = "undeployment success"
)
// Event is a log of an event taking place during deployment
// or undeployment of a router.
type Event struct {
Model
// Router id this event is for
RouterID ID `json:"-"`
Router *Router `json:"-"`
// Version of router that triggered this deployment event.
// May not necessarily pertain to the resource described by the event,
// e.g. for removal of old versions, version will point to the new version
// that triggered the event.
Version uint `json:"version"`
// EventType type of event
EventType EventType `json:"event_type"`
// Stage of deployment/undeployment
Stage EventStage `json:"stage"`
// Message describing the event
Message string `json:"message"`
}
// NewErrorEvent creates a new error event
func NewErrorEvent(stage EventStage, message string, args ...interface{}) *Event {
return newEvent(stage, EventTypeError, message, args...)
}
// NewInfoEvent creates a new info event
func NewInfoEvent(stage EventStage, message string, args ...interface{}) *Event {
return newEvent(stage, EventTypeInfo, message, args...)
}
func newEvent(stage EventStage, eventType EventType, message string, args ...interface{}) *Event {
if len(args) > 0 {
message = fmt.Sprintf(message, args...)
}
return &Event{
Stage: stage,
EventType: eventType,
Message: message,
}
}
func (e *Event) SetRouter(router *Router) {
e.RouterID = router.ID
}
func (e *Event) SetVersion(version uint) {
e.Version = version
}