MCPcopy
hub / github.com/containerd/containerd / ShowProgress

Function ShowProgress

cmd/ctr/commands/content/fetch.go:213–328  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

211// ShowProgress continuously updates the output with job progress
212// by checking status in the content store.
213func 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
223outer:
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]

Callers 1

FetchFunction · 0.85

Calls 11

FlushMethod · 0.95
NewWriterFunction · 0.92
MakeRefKeyFunction · 0.92
IsResolvedMethod · 0.80
JobsMethod · 0.80
DisplayFunction · 0.70
StopMethod · 0.65
ListStatusesMethod · 0.65
InfoMethod · 0.65
DoneMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…