-
Notifications
You must be signed in to change notification settings - Fork 3
/
events.go
68 lines (58 loc) · 1.48 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
package hush
import (
"fmt"
"time"
"github.com/itchio/hush/bfs"
)
type InstallEventSink struct {
Append func(ev InstallEvent) error
}
func (ies *InstallEventSink) PostEvent(event InstallEvent) error {
if ies == nil {
return nil
}
event.Timestamp = time.Now()
switch true {
case event.Install != nil:
event.Type = InstallEventInstall
case event.Heal != nil:
event.Type = InstallEventHeal
case event.Upgrade != nil:
event.Type = InstallEventUpgrade
case event.Problem != nil:
event.Type = InstallEventProblem
case event.GhostBusting != nil:
event.Type = InstallEventGhostBusting
case event.Patching != nil:
event.Type = InstallEventPatching
case event.Fallback != nil:
event.Type = InstallEventFallback
}
if event.Type == "" {
// wee runtime checks
panic("InstallEventSink events should always have Type set")
}
return ies.Append(event)
}
func (ies *InstallEventSink) PostProblem(err error) error {
prob := ies.MakeProblem(err)
return ies.PostEvent(InstallEvent{
Type: InstallEventProblem,
Problem: &prob,
})
}
func (ies *InstallEventSink) MakeProblem(err error) ProblemInstallEvent {
return ProblemInstallEvent{
Error: fmt.Sprintf("%v", err),
ErrorStack: fmt.Sprintf("%+v", err),
}
}
func (ies *InstallEventSink) PostGhostBusting(operation string, stats bfs.BustGhostStats) error {
return ies.PostEvent(InstallEvent{
GhostBusting: &GhostBustingInstallEvent{
Operation: "heal",
Found: stats.Found,
Removed: stats.Removed,
},
})
}