-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.go
40 lines (37 loc) · 873 Bytes
/
worker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
protos "github.com/Pixelgaffer/dico-proto"
log "github.com/Sirupsen/logrus"
)
// Worker is directly linked to a Connection
type Worker struct {
connection *Connection
taskStatusChan chan *protos.TaskStatus
taskResultChan chan *protos.TaskResult
active bool
}
func (w *Worker) consume() {
stats.Pulse()
log.WithField("name", w.connection.name()).Info("worker started consuming")
var task *Task
for {
select {
case <-w.connection.doneCh:
log.WithField("name", w.connection.name()).Info("worker stopped consuming")
w.active = false
return
case task = <-taskChan:
}
task.worker = w
w.active = true
task.execute(w.connection)
w.active = false
if task.failed {
retryChan <- task
log.WithFields(log.Fields{
"id": task.id,
"options": task.options,
}).Info("resubmitted task")
}
}
}