Update returns nil or a rendered progress update for the end user.
(msg jsonmessage.JSONMessage)
| 111 | |
| 112 | // Update returns nil or a rendered progress update for the end user. |
| 113 | func (f *pullLogFormatter) Update(msg jsonmessage.JSONMessage) *string { |
| 114 | if msg.Error != nil { |
| 115 | logrus.Errorf("%d: %v", msg.Error.Code, msg.Error.Message) |
| 116 | return nil |
| 117 | } |
| 118 | |
| 119 | var info *pullInfo |
| 120 | var ok bool |
| 121 | |
| 122 | switch msg.Status { |
| 123 | case "Pulling fs layer", "Waiting": |
| 124 | if _, ok = f.Known[msg.ID]; !ok { |
| 125 | // New layer! |
| 126 | f.Known[msg.ID] = &pullInfo{} |
| 127 | f.Order = append(f.Order, msg.ID) |
| 128 | } |
| 129 | return nil |
| 130 | |
| 131 | case "Downloading": |
| 132 | if info, ok = f.Known[msg.ID]; !ok { |
| 133 | logrus.Error("message ID not found for downloading message!") |
| 134 | return nil |
| 135 | } |
| 136 | if info.ExtractStarted { |
| 137 | logrus.Error("got downloading message after extraction started!") |
| 138 | return nil |
| 139 | } |
| 140 | info.Downloaded = msg.Progress.Current |
| 141 | // The first "Downloading" msg is important, as it gives us the layer size. |
| 142 | if !info.DownloadStarted { |
| 143 | info.DownloadStarted = true |
| 144 | info.Total = msg.Progress.Total |
| 145 | } |
| 146 | return f.backoffOrRenderProgress() |
| 147 | |
| 148 | case "Extracting": |
| 149 | if info, ok = f.Known[msg.ID]; !ok { |
| 150 | logrus.Error("message ID not found for extracting message!") |
| 151 | return nil |
| 152 | } |
| 153 | info.Extracted = msg.Progress.Current |
| 154 | if !info.ExtractStarted { |
| 155 | info.ExtractStarted = true |
| 156 | // Forcibly mark Downloaded as completed. |
| 157 | info.Downloaded = info.Total |
| 158 | } |
| 159 | return f.backoffOrRenderProgress() |
| 160 | |
| 161 | case "Pull complete": |
| 162 | if info, ok = f.Known[msg.ID]; !ok { |
| 163 | logrus.Error("message ID not found for completed message!") |
| 164 | return nil |
| 165 | } |
| 166 | // Forcibly mark Extracted as completed. |
| 167 | info.Extracted = info.Total |
| 168 | return f.backoffOrRenderProgress() |
| 169 | } |
| 170 |
no test coverage detected