-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscheduler.go
66 lines (56 loc) · 1.43 KB
/
scheduler.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
package main
import (
"fmt"
"os"
"time"
"github.com/doomsday-project/doomsday/client/doomsday"
"github.com/olekukonko/tablewriter"
"github.com/starkandwayne/goutils/ansi"
)
type schedulerCmd struct{}
func (*schedulerCmd) Run() error {
state, err := client.GetSchedulerState()
if err != nil {
return err
}
header := tablewriter.NewWriter(os.Stdout)
header.SetHeader([]string{"RUNNING"})
header.SetHeaderLine(false)
header.Render()
printSchedTaskList(state.Running)
header = tablewriter.NewWriter(os.Stdout)
header.SetHeader([]string{"PENDING"})
header.SetHeaderLine(false)
header.Render()
printSchedTaskList(state.Pending)
return nil
}
func printSchedTaskList(tasks []doomsday.GetSchedulerTask) {
fmt.Printf("\n")
table := tablewriter.NewWriter(os.Stdout)
table.SetBorder(false)
table.SetRowLine(true)
table.SetAutoWrapText(false)
table.SetReflowDuringAutoWrap(false)
table.SetHeader([]string{"At", "Backend", "Kind", "Reason", "Ready"})
table.SetAlignment(tablewriter.ALIGN_RIGHT)
readyStr := ansi.Sprintf("@G{YES}")
notReadyStr := ansi.Sprintf("@R{NO}")
now := time.Now()
for _, task := range tasks {
timeUntilStr := time.Unix(task.At, 0).Sub(now).Truncate(100 * time.Millisecond).String()
readyOutStr := notReadyStr
if task.Ready {
readyOutStr = readyStr
}
table.Append([]string{
timeUntilStr,
task.Backend,
task.Kind,
task.Reason,
readyOutStr,
})
}
table.Render()
fmt.Printf("\n")
}