mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-05 14:24:02 +02:00
chore: enhance tasks debuggability
This commit is contained in:
parent
53a78706e4
commit
57da345335
2 changed files with 14 additions and 17 deletions
|
@ -2,6 +2,7 @@ package task
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"iter"
|
"iter"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,19 +43,12 @@ func (t *Task) Key() string {
|
||||||
return t.name
|
return t.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func toBool(v uint32) bool {
|
|
||||||
if v > 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *Task) callbackList() []map[string]any {
|
func (t *Task) callbackList() []map[string]any {
|
||||||
list := make([]map[string]any, 0, len(t.callbacks))
|
list := make([]map[string]any, 0, len(t.callbacks))
|
||||||
for cb := range t.callbacks {
|
for cb := range t.callbacks {
|
||||||
list = append(list, map[string]any{
|
list = append(list, map[string]any{
|
||||||
"about": cb.about,
|
"about": cb.about,
|
||||||
"wait_children": cb.waitChildren,
|
"wait_children": strconv.FormatBool(cb.waitChildren),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
|
@ -62,9 +56,10 @@ func (t *Task) callbackList() []map[string]any {
|
||||||
|
|
||||||
func (t *Task) MarshalMap() map[string]any {
|
func (t *Task) MarshalMap() map[string]any {
|
||||||
return map[string]any{
|
return map[string]any{
|
||||||
"name": t.name,
|
"name": t.name,
|
||||||
"childrens": t.children,
|
"need_finish": strconv.FormatBool(t.needFinish),
|
||||||
"callbacks": t.callbackList(),
|
"childrens": t.children,
|
||||||
"finishCalled": toBool(t.finishedCalled),
|
"callbacks": t.callbackList(),
|
||||||
|
"finish_called": t.finishedCalled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,8 @@ type (
|
||||||
callbacks map[*Callback]struct{}
|
callbacks map[*Callback]struct{}
|
||||||
callbacksDone chan struct{}
|
callbacksDone chan struct{}
|
||||||
|
|
||||||
finished chan struct{}
|
needFinish bool
|
||||||
|
finished chan struct{}
|
||||||
// finishedCalled == 1 Finish has been called
|
// finishedCalled == 1 Finish has been called
|
||||||
// but does not mean that the task is finished yet
|
// but does not mean that the task is finished yet
|
||||||
// this is used to avoid calling Finish twice
|
// this is used to avoid calling Finish twice
|
||||||
|
@ -145,10 +146,11 @@ func (t *Task) Subtask(name string, needFinish ...bool) *Task {
|
||||||
|
|
||||||
ctx, cancel := context.WithCancelCause(t.ctx)
|
ctx, cancel := context.WithCancelCause(t.ctx)
|
||||||
child := &Task{
|
child := &Task{
|
||||||
parent: t,
|
parent: t,
|
||||||
finished: make(chan struct{}),
|
needFinish: nf,
|
||||||
ctx: ctx,
|
finished: make(chan struct{}),
|
||||||
cancel: cancel,
|
ctx: ctx,
|
||||||
|
cancel: cancel,
|
||||||
}
|
}
|
||||||
if t != root {
|
if t != root {
|
||||||
child.name = t.name + "." + name
|
child.name = t.name + "." + name
|
||||||
|
|
Loading…
Add table
Reference in a new issue