-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
68 lines (54 loc) · 1.3 KB
/
helper.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package nsq
import (
"encoding/json"
faktory "github.com/contribsys/faktory/client"
"github.com/nsqio/go-nsq"
"github.com/toby1991/go-zero-utils/queue"
"time"
)
type helper struct {
message *nsq.Message
job *queue.Job
}
func HelperFor(message *nsq.Message) (*helper, error) {
var job queue.Job
if err := json.Unmarshal(message.Body, &job); err != nil {
return nil, err
}
return &helper{message: message, job: &job}, nil
}
func (h *helper) Job() *queue.Job {
return h.job
}
func (h *helper) Jid() string {
//return string(hash.Md5(h.message.ID[:]))
return string(h.message.ID[:])
}
// Channel = job.Type
func (h *helper) JobType() string {
return h.Job().Type
}
func (h *helper) Custom(key string) (value interface{}, ok bool) {
val, ok := h.Job().Custom[key]
return val, ok
}
func (h *helper) Bid() string {
//TODO implement me
return string(h.message.ID[:])
}
func (h *helper) CallbackBid() string {
//TODO implement me
panic("implement me")
}
func (h *helper) Batch(f func(*faktory.Batch) error) error {
//TODO implement me
panic("implement me")
}
func (h *helper) With(f func(*faktory.Client) error) error {
//TODO implement me
panic("implement me")
}
func (h *helper) TrackProgress(percent int, desc string, reserveUntil *time.Time) error {
//TODO implement me
panic("implement me")
}