(prefix string, jm jsonstream.Message, events api.EventProcessor)
| 130 | } |
| 131 | |
| 132 | func 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 | |
| 174 | func isDone(msg jsonstream.Message) bool { |
| 175 | // TODO there should be a better way to detect push is done than such a status message check |
no test coverage detected