mirror of
https://github.com/hibiken/asynq.git
synced 2025-10-03 05:12:01 +08:00
(cli): Update debug info
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@@ -47,6 +48,46 @@ type State struct {
|
||||
prevView viewType // to support "go back"
|
||||
}
|
||||
|
||||
func (s *State) DebugString() string {
|
||||
var b strings.Builder
|
||||
b.WriteString(fmt.Sprintf("len(queues)=%d ", len(s.queues)))
|
||||
b.WriteString(fmt.Sprintf("len(tasks)=%d ", len(s.tasks)))
|
||||
b.WriteString(fmt.Sprintf("len(groups)=%d ", len(s.groups)))
|
||||
b.WriteString(fmt.Sprintf("err=%v ", s.err))
|
||||
|
||||
if s.taskState != 0 {
|
||||
b.WriteString(fmt.Sprintf("taskState=%s ", s.taskState.String()))
|
||||
} else {
|
||||
b.WriteString(fmt.Sprintf("taskState=0"))
|
||||
}
|
||||
b.WriteString(fmt.Sprintf("taskID=%s ", s.taskID))
|
||||
|
||||
b.WriteString(fmt.Sprintf("queueTableRowIdx=%d ", s.queueTableRowIdx))
|
||||
b.WriteString(fmt.Sprintf("taskTableRowIdx=%d ", s.taskTableRowIdx))
|
||||
b.WriteString(fmt.Sprintf("groupTableRowIdx=%d ", s.groupTableRowIdx))
|
||||
|
||||
if s.selectedQueue != nil {
|
||||
b.WriteString(fmt.Sprintf("selectedQueue={Queue:%s} ", s.selectedQueue.Queue))
|
||||
} else {
|
||||
b.WriteString("selectedQueue=nil ")
|
||||
}
|
||||
|
||||
if s.selectedGroup != nil {
|
||||
b.WriteString(fmt.Sprintf("selectedGroup={Group:%s} ", s.selectedGroup.Group))
|
||||
} else {
|
||||
b.WriteString("selectedGroup=nil ")
|
||||
}
|
||||
|
||||
if s.selectedTask != nil {
|
||||
b.WriteString(fmt.Sprintf("selectedTask={ID:%s} ", s.selectedTask.ID))
|
||||
} else {
|
||||
b.WriteString("selectedTask=nil ")
|
||||
}
|
||||
|
||||
b.WriteString(fmt.Sprintf("pageNum=%d", s.pageNum))
|
||||
return b.String()
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
DebugMode bool
|
||||
PollInterval time.Duration
|
||||
|
@@ -62,13 +62,12 @@ func (dd *dashDrawer) Draw(state *State) {
|
||||
d.NL()
|
||||
// TODO: Draw HELP body
|
||||
}
|
||||
if opts.DebugMode {
|
||||
d.Println(fmt.Sprintf("DEBUG: rowIdx = %d", state.queueTableRowIdx), baseStyle)
|
||||
d.Println(fmt.Sprintf("DEBUG: selectedQueue = %s", state.selectedQueue.Queue), baseStyle)
|
||||
d.Println(fmt.Sprintf("DEBUG: view = %v", state.view), baseStyle)
|
||||
}
|
||||
d.GoToBottom()
|
||||
if opts.DebugMode {
|
||||
drawDebugInfo(d, state)
|
||||
} else {
|
||||
drawFooter(d, state)
|
||||
}
|
||||
}
|
||||
|
||||
func drawQueueSizeGraphs(d *ScreenDrawer, state *State) {
|
||||
@@ -667,3 +666,7 @@ func truncate(s string, max int) string {
|
||||
}
|
||||
return string([]rune(s)[:max-1]) + "…"
|
||||
}
|
||||
|
||||
func drawDebugInfo(d *ScreenDrawer, state *State) {
|
||||
d.Println(state.DebugString(), baseStyle)
|
||||
}
|
||||
|
Reference in New Issue
Block a user