ShowProgress continuously updates the output with job progress by checking status in the content store.
(ctx context.Context, ongoing *Jobs, cs content.Store, out io.Writer)
| 211 | // ShowProgress continuously updates the output with job progress |
| 212 | // by checking status in the content store. |
| 213 | func ShowProgress(ctx context.Context, ongoing *Jobs, cs content.Store, out io.Writer) { |
| 214 | var ( |
| 215 | ticker = time.NewTicker(100 * time.Millisecond) |
| 216 | fw = progress.NewWriter(out) |
| 217 | start = time.Now() |
| 218 | statuses = map[string]StatusInfo{} |
| 219 | done bool |
| 220 | ) |
| 221 | defer ticker.Stop() |
| 222 | |
| 223 | outer: |
| 224 | for { |
| 225 | select { |
| 226 | case <-ticker.C: |
| 227 | fw.Flush() |
| 228 | |
| 229 | tw := tabwriter.NewWriter(fw, 1, 8, 1, ' ', 0) |
| 230 | |
| 231 | resolved := StatusResolved |
| 232 | if !ongoing.IsResolved() { |
| 233 | resolved = StatusResolving |
| 234 | } |
| 235 | statuses[ongoing.name] = StatusInfo{ |
| 236 | Ref: ongoing.name, |
| 237 | Status: resolved, |
| 238 | } |
| 239 | keys := []string{ongoing.name} |
| 240 | |
| 241 | activeSeen := map[string]struct{}{} |
| 242 | if !done { |
| 243 | active, err := cs.ListStatuses(ctx, "") |
| 244 | if err != nil { |
| 245 | log.G(ctx).WithError(err).Error("active check failed") |
| 246 | continue |
| 247 | } |
| 248 | // update status of active entries! |
| 249 | for _, active := range active { |
| 250 | statuses[active.Ref] = StatusInfo{ |
| 251 | Ref: active.Ref, |
| 252 | Status: StatusDownloading, |
| 253 | Offset: active.Offset, |
| 254 | Total: active.Total, |
| 255 | StartedAt: active.StartedAt, |
| 256 | UpdatedAt: active.UpdatedAt, |
| 257 | } |
| 258 | activeSeen[active.Ref] = struct{}{} |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | // now, update the items in jobs that are not in active |
| 263 | for _, j := range ongoing.Jobs() { |
| 264 | key := remotes.MakeRefKey(ctx, j) |
| 265 | keys = append(keys, key) |
| 266 | if _, ok := activeSeen[key]; ok { |
| 267 | continue |
| 268 | } |
| 269 | |
| 270 | status, ok := statuses[key] |
no test coverage detected
searching dependent graphs…