-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtube.go
54 lines (48 loc) · 1.02 KB
/
tube.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
package main
import (
"encoding/json"
)
type Tube struct {
deps []string
name string
reserved uint
ready uint
delayed uint
pause uint
}
func NewTube(name string, reserved, ready, delayed, pause uint) *Tube {
this := new(Tube)
this.name = name
this.reserved = reserved
this.ready = ready
this.delayed = delayed
this.pause = pause
this.deps = make([]string, 0)
if deps, found := Config.deps[name]; found {
this.deps = deps[:]
}
return this
}
func (this *Tube) Jobs() uint {
return this.delayed + this.ready + this.reserved
}
func (this *Tube) Ready(queue map[string]*Tube) bool {
for _, dep := range this.deps {
if tube, found := queue[dep]; found {
if tube.Jobs() > 0 {
return false
}
}
}
return true
}
func (this *Tube) MarshalJSON() ([]byte, error) {
stats := make(map[string]interface{})
stats["jobs-ready"] = this.ready
stats["jobs-reserved"] = this.reserved
stats["jobs-delayed"] = this.delayed
if this.pause != 0 {
stats["pause"] = this.pause
}
return json.Marshal(stats)
}