-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.go
81 lines (68 loc) · 1.42 KB
/
data.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 machine
import (
"fmt"
"os"
"time"
"github.com/Sirupsen/logrus"
)
type machinesData struct {
Runner string
Acquired int
Creating int
Idle int
Used int
Removing int
StuckOnRemoving int
}
func (d *machinesData) Available() int {
return d.Acquired + d.Creating + d.Idle
}
func (d *machinesData) Total() int {
return d.Acquired + d.Creating + d.Idle + d.Used + d.Removing + d.StuckOnRemoving
}
func (d *machinesData) Add(details *machineDetails) {
switch details.State {
case machineStateIdle:
d.Idle++
case machineStateCreating:
d.Creating++
case machineStateAcquired:
d.Acquired++
case machineStateUsed:
d.Used++
case machineStateRemoving:
if details.isStuckOnRemove() {
d.StuckOnRemoving++
} else {
d.Removing++
}
}
}
func (d *machinesData) Fields() logrus.Fields {
return logrus.Fields{
"runner": d.Runner,
"used": d.Used,
"idle": d.Idle,
"total": d.Total(),
"creating": d.Creating,
"removing": d.Removing,
}
}
func (d *machinesData) writeDebugInformation() {
if logrus.GetLevel() < logrus.DebugLevel {
return
}
file, err := os.OpenFile("machines.csv", os.O_RDWR|os.O_APPEND, 0600)
if err != nil {
return
}
defer file.Close()
fmt.Fprintln(file,
"time", time.Now(),
"runner", d.Runner,
"acquired", d.Acquired,
"creating", d.Creating,
"idle", d.Idle,
"used", d.Used,
"removing", d.Removing)
}