worker loops forever, running queued tasks one at a time. Any returned errors are logged.
()
| 210 | |
| 211 | // worker loops forever, running queued tasks one at a time. Any returned errors are logged. |
| 212 | func (t *tasks) worker() { |
| 213 | shouldCleanup := time.Tick(time.Hour) |
| 214 | |
| 215 | for { |
| 216 | // If the server is shutting down, return immediately. Else, fetch a task from the queue. |
| 217 | var task taskRequest |
| 218 | select { |
| 219 | case <-x.ServerCloser.HasBeenClosed(): |
| 220 | if err := t.log.Close(); err != nil { |
| 221 | glog.Warningf("error closing log file: %v", err) |
| 222 | } |
| 223 | return |
| 224 | case <-shouldCleanup: |
| 225 | t.cleanup() |
| 226 | case task = <-t.queue: |
| 227 | if err := t.run(task); err != nil { |
| 228 | glog.Errorf("task %#x: failed: %s", task.id, err) |
| 229 | } else { |
| 230 | glog.Infof("task %#x: completed successfully", task.id) |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | func (t *tasks) run(task taskRequest) error { |
| 237 | // Fetch the task from the log. If the task isn't found, this means it has expired (older than |