Skip to content

Commit

Permalink
opt: Status display when sync is complete (#5313)
Browse files Browse the repository at this point in the history
Co-authored-by: 一页素书 <[email protected]>
  • Loading branch information
diwufeiwen and ta0li authored Sep 22, 2022
1 parent 2c1e52a commit 6afaaf6
Showing 1 changed file with 43 additions and 27 deletions.
70 changes: 43 additions & 27 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,49 +62,65 @@ var storeStatusCmd = &cmds.Command{
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error {
tracker := env.(*node.Env).SyncerAPI.SyncerTracker(req.Context)
targets := tracker.Buckets
w := bytes.NewBufferString("")
writer := NewSilentWriter(w)

var inSyncing []*types.Target
var waitTarget []*types.Target

for _, t := range targets {
if t.State == types.SyncStateStage(syncTypes.StateInSyncing) {
inSyncing = append(inSyncing, t)
} else {
waitTarget = append(waitTarget, t)
}
}

w := bytes.NewBufferString("")
writer := NewSilentWriter(w)

if len(inSyncing) == 0 && len(waitTarget) == 0 {
lenTH := len(tracker.History)
if lenTH > 0 {
writer.Println(tracker.History[lenTH-1].String())
}

writer.Println("Done!")
return re.Emit(w)
}

count := 1
writer.Println("Syncing:")
for _, t := range inSyncing {
writer.Println("SyncTarget:", strconv.Itoa(count))
writer.Println("\tBase:", t.Base.Height(), t.Base.Key().String())
writer.Println("\tTarget:", t.Head.Height(), t.Head.Key().String())
writer.Println("\tCurrent:", t.Current.Height(), t.Current.Key().String())
if len(inSyncing) > 0 {
writer.Println("Syncing:")
for _, t := range inSyncing {
writer.Println("SyncTarget:", strconv.Itoa(count))
writer.Println("\tBase:", t.Base.Height(), t.Base.Key().String())
writer.Println("\tTarget:", t.Head.Height(), t.Head.Key().String())
writer.Println("\tCurrent:", t.Current.Height(), t.Current.Key().String())

HeightDiff := t.Head.Height() - t.Current.Height()
writer.Println("\tHeightDiff:", HeightDiff)
HeightDiff := t.Head.Height() - t.Current.Height()
writer.Println("\tHeightDiff:", HeightDiff)

writer.Println("\tStatus:", t.State.String())
writer.Println("\tErr:", t.Err)
writer.Println()
count++
writer.Println("\tStatus:", t.State.String())
writer.Println("\tErr:", t.Err)
writer.Println()
count++
}
}

writer.Println("Waiting:")
for _, t := range waitTarget {
writer.Println("SyncTarget:", strconv.Itoa(count))
writer.Println("\tBase:", t.Base.Height(), t.Base.Key().String())
writer.Println("\tTarget:", t.Head.Height(), t.Head.Key().String())
writer.Println("\tCurrent:", t.Current.Height(), t.Current.Key().String())
if len(waitTarget) > 0 {
writer.Println("Waiting:")
for _, t := range waitTarget {
writer.Println("SyncTarget:", strconv.Itoa(count))
writer.Println("\tBase:", t.Base.Height(), t.Base.Key().String())
writer.Println("\tTarget:", t.Head.Height(), t.Head.Key().String())
writer.Println("\tCurrent:", t.Current.Height(), t.Current.Key().String())

HeightDiff := t.Head.Height() - t.Current.Height()
writer.Println("\tHeightDiff:", HeightDiff)
HeightDiff := t.Head.Height() - t.Current.Height()
writer.Println("\tHeightDiff:", HeightDiff)

writer.Println("\tStatus:", t.State.String())
writer.Println("\tErr:", t.Err)
writer.Println()
count++
writer.Println("\tStatus:", t.State.String())
writer.Println("\tErr:", t.Err)
writer.Println()
count++
}
}

return re.Emit(w)
Expand Down

0 comments on commit 6afaaf6

Please sign in to comment.