-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwrapper.go
More file actions
40 lines (32 loc) · 1.05 KB
/
Copy pathwrapper.go
File metadata and controls
40 lines (32 loc) · 1.05 KB
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 que
import (
"fmt"
"time"
"github.com/jcoene/statsd-client"
"github.com/nsqio/go-nsq"
)
type wrapper struct {
topic string
channel string
generator HandlerGenerator
}
func (w *wrapper) HandleMessage(message *nsq.Message) (err error) {
payload := &Payload{w.topic, w.channel, message}
t := time.Now()
handler, err := w.generator(payload)
if err != nil {
Logger.Error("%s: unable to generate handler for message %v: %s", w.topic, message.ID, err)
return
}
Logger.Info("%s %s: starting...", w.topic, handler.Id())
if err = handler.Perform(); err != nil {
Logger.Error("%s %s: %s in %v", w.topic, handler.Id(), err, time.Since(t))
statsd.Count(fmt.Sprintf("worker.%s.error.count", w.topic), 1)
statsd.MeasureDur(fmt.Sprintf("worker.%s.error.runtime", w.topic), time.Since(t))
} else {
Logger.Info("%s %s: completed in %v", w.topic, handler.Id(), time.Since(t))
statsd.Count(fmt.Sprintf("worker.%s.success.count", w.topic), 1)
statsd.MeasureDur(fmt.Sprintf("worker.%s.success.runtime", w.topic), time.Since(t))
}
return
}