Merge pull request #7669 from yanggangtony/status-clean

make status more readable and update easy.
This commit is contained in:
Fu Wei 2022-11-27 23:12:23 +08:00 committed by GitHub
commit 24020812bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 17 deletions

View File

@ -236,9 +236,9 @@ outer:
tw := tabwriter.NewWriter(fw, 1, 8, 1, ' ', 0) tw := tabwriter.NewWriter(fw, 1, 8, 1, ' ', 0)
resolved := "resolved" resolved := StatusResolved
if !ongoing.IsResolved() { if !ongoing.IsResolved() {
resolved = "resolving" resolved = StatusResolving
} }
statuses[ongoing.name] = StatusInfo{ statuses[ongoing.name] = StatusInfo{
Ref: ongoing.name, Ref: ongoing.name,
@ -257,7 +257,7 @@ outer:
for _, active := range active { for _, active := range active {
statuses[active.Ref] = StatusInfo{ statuses[active.Ref] = StatusInfo{
Ref: active.Ref, Ref: active.Ref,
Status: "downloading", Status: StatusDownloading,
Offset: active.Offset, Offset: active.Offset,
Total: active.Total, Total: active.Total,
StartedAt: active.StartedAt, StartedAt: active.StartedAt,
@ -276,7 +276,7 @@ outer:
} }
status, ok := statuses[key] status, ok := statuses[key]
if !done && (!ok || status.Status == "downloading") { if !done && (!ok || status.Status == StatusDownloading) {
info, err := cs.Info(ctx, j.Digest) info, err := cs.Info(ctx, j.Digest)
if err != nil { if err != nil {
if !errdefs.IsNotFound(err) { if !errdefs.IsNotFound(err) {
@ -285,13 +285,13 @@ outer:
} else { } else {
statuses[key] = StatusInfo{ statuses[key] = StatusInfo{
Ref: key, Ref: key,
Status: "waiting", Status: StatusWaiting,
} }
} }
} else if info.CreatedAt.After(start) { } else if info.CreatedAt.After(start) {
statuses[key] = StatusInfo{ statuses[key] = StatusInfo{
Ref: key, Ref: key,
Status: "done", Status: StatusDone,
Offset: info.Size, Offset: info.Size,
Total: info.Size, Total: info.Size,
UpdatedAt: info.CreatedAt, UpdatedAt: info.CreatedAt,
@ -299,19 +299,19 @@ outer:
} else { } else {
statuses[key] = StatusInfo{ statuses[key] = StatusInfo{
Ref: key, Ref: key,
Status: "exists", Status: StatusExists,
} }
} }
} else if done { } else if done {
if ok { if ok {
if status.Status != "done" && status.Status != "exists" { if status.Status != StatusDone && status.Status != StatusExists {
status.Status = "done" status.Status = StatusDone
statuses[key] = status statuses[key] = status
} }
} else { } else {
statuses[key] = StatusInfo{ statuses[key] = StatusInfo{
Ref: key, Ref: key,
Status: "done", Status: StatusDone,
} }
} }
} }
@ -385,10 +385,24 @@ func (j *Jobs) IsResolved() bool {
return j.resolved return j.resolved
} }
// StatusInfoStatus describes status info for an upload or download.
type StatusInfoStatus string
const (
StatusResolved StatusInfoStatus = "resolved"
StatusResolving StatusInfoStatus = "resolving"
StatusWaiting StatusInfoStatus = "waiting"
StatusCommitting StatusInfoStatus = "committing"
StatusDone StatusInfoStatus = "done"
StatusDownloading StatusInfoStatus = "downloading"
StatusUploading StatusInfoStatus = "uploading"
StatusExists StatusInfoStatus = "exists"
)
// StatusInfo holds the status info for an upload or download // StatusInfo holds the status info for an upload or download
type StatusInfo struct { type StatusInfo struct {
Ref string Ref string
Status string Status StatusInfoStatus
Offset int64 Offset int64
Total int64 Total int64
StartedAt time.Time StartedAt time.Time
@ -401,7 +415,7 @@ func Display(w io.Writer, statuses []StatusInfo, start time.Time) {
for _, status := range statuses { for _, status := range statuses {
total += status.Offset total += status.Offset
switch status.Status { switch status.Status {
case "downloading", "uploading": case StatusDownloading, StatusUploading:
var bar progress.Bar var bar progress.Bar
if status.Total > 0.0 { if status.Total > 0.0 {
bar = progress.Bar(float64(status.Offset) / float64(status.Total)) bar = progress.Bar(float64(status.Offset) / float64(status.Total))
@ -411,7 +425,7 @@ func Display(w io.Writer, statuses []StatusInfo, start time.Time) {
status.Status, status.Status,
bar, bar,
progress.Bytes(status.Offset), progress.Bytes(status.Total)) progress.Bytes(status.Offset), progress.Bytes(status.Total))
case "resolving", "waiting": case StatusResolving, StatusWaiting:
bar := progress.Bar(0.0) bar := progress.Bar(0.0)
fmt.Fprintf(w, "%s:\t%s\t%40r\t\n", fmt.Fprintf(w, "%s:\t%s\t%40r\t\n",
status.Ref, status.Ref,

View File

@ -247,7 +247,7 @@ func (j *pushjobs) status() []content.StatusInfo {
status, err := j.tracker.GetStatus(name) status, err := j.tracker.GetStatus(name)
if err != nil { if err != nil {
si.Status = "waiting" si.Status = content.StatusWaiting
} else { } else {
si.Offset = status.Offset si.Offset = status.Offset
si.Total = status.Total si.Total = status.Total
@ -255,12 +255,12 @@ func (j *pushjobs) status() []content.StatusInfo {
si.UpdatedAt = status.UpdatedAt si.UpdatedAt = status.UpdatedAt
if status.Offset >= status.Total { if status.Offset >= status.Total {
if status.UploadUUID == "" { if status.UploadUUID == "" {
si.Status = "done" si.Status = content.StatusDone
} else { } else {
si.Status = "committing" si.Status = content.StatusCommitting
} }
} else { } else {
si.Status = "uploading" si.Status = content.StatusUploading
} }
} }
statuses = append(statuses, si) statuses = append(statuses, si)