github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/plugin/progress.go (about) 1 package plugin 2 3 import ( 4 "sync" 5 "time" 6 7 "github.com/containerd/containerd/remotes/docker" 8 ) 9 10 func newPushJobs(tracker docker.StatusTracker) *pushJobs { 11 return &pushJobs{ 12 names: make(map[string]string), 13 t: tracker, 14 } 15 } 16 17 type pushJobs struct { 18 t docker.StatusTracker 19 20 mu sync.Mutex 21 jobs []string 22 // maps job ref to a name 23 names map[string]string 24 } 25 26 func (p *pushJobs) add(id, name string) { 27 p.mu.Lock() 28 defer p.mu.Unlock() 29 30 if _, ok := p.names[id]; ok { 31 return 32 } 33 p.jobs = append(p.jobs, id) 34 p.names[id] = name 35 } 36 37 func (p *pushJobs) status() []contentStatus { 38 statuses := make([]contentStatus, 0, len(p.jobs)) 39 40 p.mu.Lock() 41 defer p.mu.Unlock() 42 43 for _, j := range p.jobs { 44 var s contentStatus 45 s.Ref = p.names[j] 46 47 status, err := p.t.GetStatus(j) 48 if err != nil { 49 s.Status = "Waiting" 50 } else { 51 s.Total = status.Total 52 s.Offset = status.Offset 53 s.StartedAt = status.StartedAt 54 s.UpdatedAt = status.UpdatedAt 55 if status.UploadUUID == "" { 56 s.Status = "Upload complete" 57 } else { 58 s.Status = "Uploading" 59 } 60 } 61 statuses = append(statuses, s) 62 } 63 64 return statuses 65 } 66 67 type contentStatus struct { 68 Status string 69 Total int64 70 Offset int64 71 StartedAt time.Time 72 UpdatedAt time.Time 73 Ref string 74 }