-
Notifications
You must be signed in to change notification settings - Fork 0
/
producer.go
52 lines (41 loc) · 1.08 KB
/
producer.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
package queue
import (
"gopkg.in/go-mixed/framework.v1/container"
"time"
"gopkg.in/go-mixed/framework.v1/contracts/queue"
)
type Producer struct {
Chain bool
Jobs []queue.IBrokerJob
connection string
queue string
eta *time.Time
}
var _ queue.IProducer = (*Producer)(nil)
func NewProducer() *Producer {
return &Producer{}
}
func (p *Producer) AddJob(job queue.IBrokerJob) queue.IProducer {
p.Jobs = append(p.Jobs, job)
return p
}
func (p *Producer) Dispatch() error {
b := container.MustMakeAs("queue.manager", (*QueueManager)(nil)).Connection(p.connection)
return b.AddJobWithQueue(p.queue, p.Jobs...)
}
func (p *Producer) DispatchSync() error {
b := container.MustMakeAs("queue.manager", (*QueueManager)(nil)).Connection("sync")
return b.AddJobWithQueue(p.queue, p.Jobs...)
}
func (p *Producer) OnConnection(connection string) queue.IProducer {
p.connection = connection
return p
}
func (p *Producer) OnQueue(queue string) queue.IProducer {
p.queue = queue
return p
}
func (p *Producer) Delay(eta time.Time) queue.IProducer {
p.eta = &eta
return p
}