-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory.go
49 lines (38 loc) · 945 Bytes
/
history.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
package job
import (
"fmt"
"tools/queue"
)
func NewHistory(waitQueueLen int) *HistoryJobList {
return &HistoryJobList{
JobList: queue.New(waitQueueLen),
}
}
func (h *HistoryJobList) Add(j *Job) {
j.Id = int32(h.JobList.Bottom % h.JobList.Maxlen)
h.JobList.EnQueue(j)
}
func (h *HistoryJobList) List() []interface{} {
return h.JobList.Elems
}
func (h *HistoryJobList) Update(j *Job, status string) {
jo := h.JobList.Elems[j.Id].(*Job)
jo.Status = status
// for test
h.Watch()
}
func (h *HistoryJobList) Watch() {
var start, end int
if h.JobList.Full {
start, end = h.JobList.Top, h.JobList.Maxlen
} else {
start, end = h.JobList.Top, h.JobList.Bottom
}
fmt.Printf("----------- %d ----------\n", len(h.JobList.Elems))
for i := start; i < end; i++ {
fmt.Println(i)
jo := h.JobList.Elems[i].(*Job)
fmt.Printf("[%d] %s, %s\n", jo.Id, jo.Status, jo.Image+":"+jo.Tag)
}
fmt.Println("----------------------")
}