-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscheduler.go
52 lines (45 loc) · 1.04 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
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
}
printSchedTaskList(state.Tasks)
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", "Reason", "Kind", "Ready"})
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).String()
readyOutStr := notReadyStr
if task.Ready {
readyOutStr = readyStr
}
table.Append([]string{
timeUntilStr,
task.Reason,
task.Kind,
readyOutStr,
})
}
table.Render()
fmt.Printf("\n")
}