update adjusts task state based on last received event
(e api.Resource)
| 104 | |
| 105 | // update adjusts task state based on last received event |
| 106 | func (t *task) update(e api.Resource) { |
| 107 | if e.ParentID != "" { |
| 108 | t.parents.Add(e.ParentID) |
| 109 | // we may receive same event from distinct parents (typically: images sharing layers) |
| 110 | // to avoid status to flicker, only accept updates from our first declared parent |
| 111 | if t.parent != e.ParentID { |
| 112 | return |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // update task based on received event |
| 117 | switch e.Status { |
| 118 | case api.Done, api.Error, api.Warning: |
| 119 | if t.status != e.Status { |
| 120 | t.stop() |
| 121 | } |
| 122 | case api.Working: |
| 123 | t.hasMore() |
| 124 | } |
| 125 | t.status = e.Status |
| 126 | t.text = e.Text |
| 127 | t.details = e.Details |
| 128 | // progress can only go up |
| 129 | if e.Total > t.total { |
| 130 | t.total = e.Total |
| 131 | } |
| 132 | if e.Current > t.current { |
| 133 | t.current = e.Current |
| 134 | } |
| 135 | if e.Percent > t.percent { |
| 136 | t.percent = e.Percent |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | func (t *task) stop() { |
| 141 | t.endTime = time.Now() |