Reset to stable branch

This commit is contained in:
Richard Patel
2019-02-22 05:37:45 +01:00
parent 7c8ab50ee4
commit 326e29e5e4
13 changed files with 162 additions and 758 deletions

View File

@@ -1,7 +1,6 @@
package main
import (
"context"
"github.com/beeker1121/goque"
"github.com/sirupsen/logrus"
"math"
@@ -19,29 +18,10 @@ type WorkerContext struct {
Queue *BufferedQueue
lastRateLimit time.Time
numRateLimits int
workers sync.WaitGroup
aborted int32
}
func (w *WorkerContext) SpawnWorkers(c context.Context, results chan<- File, n int) {
w.workers.Add(n)
for i := 0; i < n; i++ {
go w.Worker(c, results)
}
}
func (w *WorkerContext) Worker(c context.Context, results chan<- File) {
defer w.workers.Done()
func (w *WorkerContext) Worker(results chan<- File) {
for {
select {
case <-c.Done():
// Not yet done
atomic.StoreInt32(&w.aborted, 1)
return
default:
}
job, err := w.Queue.Dequeue()
switch err {
case goque.ErrEmpty:
@@ -176,7 +156,7 @@ func (w *WorkerContext) DoJob(job *Job, f *File) (newJobs []Job, err error) {
}
func (w *WorkerContext) queueJob(job Job) {
atomic.AddInt64(&w.OD.InProgress, 1)
w.OD.Wait.Add(1)
if w.numRateLimits > 0 {
if time.Since(w.lastRateLimit) > 5 * time.Second {
@@ -193,7 +173,7 @@ func (w *WorkerContext) queueJob(job Job) {
}
func (w *WorkerContext) finishJob() {
atomic.AddInt64(&w.OD.InProgress, -1)
w.OD.Wait.Done()
}
func isErrSilent(err error) bool {