-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevent_handlers.go
115 lines (102 loc) · 3.17 KB
/
event_handlers.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package app
import (
"dockside/app/logger"
"fmt"
"github.com/google/uuid"
"github.com/maddalax/htmgo/framework/service"
"strings"
"time"
)
type EventHandler struct {
locator *service.Locator
}
func NewEventHandler(locator *service.Locator) *EventHandler {
return &EventHandler{
locator: locator,
}
}
func (eh *EventHandler) OnJobStarted(job *Job) {
registry := GetServiceRegistry(eh.locator)
logger.DebugWithFields("job started", map[string]any{
"job_name": job.name,
})
registry.GetJobMetricsManager().OnJobStarted(job)
}
func (eh *EventHandler) OnJobFinished(job *Job) {
registry := GetServiceRegistry(eh.locator)
logger.DebugWithFields("job finished", map[string]any{
"job_name": job.name,
"total_runs": job.totalRuns,
"duration": fmt.Sprintf("%dms", job.lastRunDuration.Milliseconds()),
})
registry.GetJobMetricsManager().OnJobFinished(job)
}
func (eh *EventHandler) OnJobStopped(job *Job) {
registry := GetServiceRegistry(eh.locator)
logger.DebugWithFields("job stopped", map[string]any{
"job_name": job.name,
"total_runs": job.totalRuns,
})
registry.GetJobMetricsManager().OnJobStopped(job)
}
func (eh *EventHandler) OnJobResumed(job *Job) {
registry := GetServiceRegistry(eh.locator)
logger.DebugWithFields("job resumed", map[string]any{
"job_name": job.name,
})
registry.GetJobMetricsManager().OnJobResumed(job)
}
func (eh *EventHandler) OnJobPaused(job *Job) {
registry := GetServiceRegistry(eh.locator)
logger.DebugWithFields("job paused", map[string]any{
"job_name": job.name,
})
registry.GetJobMetricsManager().OnJobPaused(job)
}
func (eh *EventHandler) OnServerDisconnected(server *Server) {
logger.InfoWithFields("server disconnected", map[string]any{
"server_id": server.Id,
"name": server.FormattedName(),
})
}
func (eh *EventHandler) OnServerConnected(server *Server) {
logger.InfoWithFields("server connected", map[string]any{
"server_id": server.Id,
"name": server.FormattedName(),
})
}
func (eh *EventHandler) OnServerDetached(serverId string, resource *Resource) {
logger.InfoWithFields("server detached from resource", map[string]any{
"server_id": serverId,
"resource_id": resource.Id,
"resource_name": resource.Name,
})
}
func (eh *EventHandler) OnResourceStatusChange(resource *Resource, status RunStatus) {
logger.InfoWithFields("resource status changed", map[string]any{
"resource_id": resource.Id,
"resource_name": resource.Name,
"new_status": status,
})
}
func (eh *EventHandler) OnNewCommit(resource *Resource, branch string, commit string) {
logger.InfoWithFields("new commit", map[string]any{
"resource_id": resource.Id,
"commit": commit,
"branch": branch,
})
switch bm := resource.BuildMeta.(type) {
case *DockerBuildMeta:
if bm.DeployOnNewCommit && strings.ToLower(bm.DeploymentBranch) == strings.ToLower(branch) {
buildId := uuid.New().String()
logger.InfoWithFields("Starting build from new commit", map[string]any{
"resource": resource.Id,
"build": buildId,
"branch": branch,
"commit": commit,
})
b := NewResourceBuilder(eh.locator, resource, buildId, fmt.Sprintf("Auto Deploy (%s)", branch))
_ = b.StartBuildAsync(time.Second)
}
}
}