Run maintains the queue and executes flushes as necessary
()
| 96 | |
| 97 | // Run maintains the queue and executes flushes as necessary |
| 98 | func (q *Queue) Run() { |
| 99 | q.smux.Lock() |
| 100 | q.stopped = false |
| 101 | q.smux.Unlock() |
| 102 | q.l.Infow("spinning up queue", "rate", q.rate) |
| 103 | var ticker = time.NewTicker(q.rate) |
| 104 | for { |
| 105 | select { |
| 106 | case <-ticker.C: |
| 107 | q.flushIfNeeded() |
| 108 | |
| 109 | case item := <-q.pendingC: |
| 110 | q.pendingItems[q.pending] = item |
| 111 | q.pending++ |
| 112 | q.flushIfNeeded() |
| 113 | |
| 114 | case <-q.stopC: |
| 115 | q.l.Infow("stopping background job") |
| 116 | ticker.Stop() |
| 117 | q.stop() |
| 118 | return |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // Close stops the queue runner and releases queue assets |
| 124 | func (q *Queue) Close() { |