MCPcopy
hub / github.com/docker/compose / toPushProgressEvent

Function toPushProgressEvent

pkg/compose/push.go:132–172  ·  pkg/compose/push.go::toPushProgressEvent
(prefix string, jm jsonstream.Message, events api.EventProcessor)

Source from the content-addressed store, hash-verified

130}
131
132func toPushProgressEvent(prefix string, jm jsonstream.Message, events api.EventProcessor) {
133 if jm.ID == "" {
134 // skipped
135 return
136 }
137 var (
138 text string
139 status = api.Working
140 total int64
141 current int64
142 percent int
143 )
144 if isDone(jm) {
145 status = api.Done
146 percent = 100
147 }
148 if jm.Error != nil {
149 status = api.Error
150 text = jm.Error.Message
151 }
152 if jm.Progress != nil {
153 text = progressText(jm.Progress)
154 if jm.Progress.Total != 0 {
155 current = jm.Progress.Current
156 total = jm.Progress.Total
157 if jm.Progress.Total > 0 {
158 percent = min(int(jm.Progress.Current*100/jm.Progress.Total), 100)
159 }
160 }
161 }
162
163 events.On(api.Resource{
164 ParentID: prefix,
165 ID: jm.ID,
166 Text: text,
167 Status: status,
168 Current: current,
169 Total: total,
170 Percent: percent,
171 })
172}
173
174func isDone(msg jsonstream.Message) bool {
175 // TODO there should be a better way to detect push is done than such a status message check

Callers 1

pushServiceImageMethod · 0.85

Calls 3

isDoneFunction · 0.85
progressTextFunction · 0.85
OnMethod · 0.65

Tested by

no test coverage detected