-
Notifications
You must be signed in to change notification settings - Fork 2
/
enqueuer.go
38 lines (30 loc) · 938 Bytes
/
enqueuer.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
package worker
import (
"strings"
"github.com/golang/protobuf/proto"
"github.com/guilhermehubner/worker/broker"
)
type Enqueuer struct {
broker *broker.AMQPBroker
}
/*
NewEnqueuer creates a new enqueuer.
URL is a string connection in the AMQP URI format.
*/
func NewEnqueuer(url string) *Enqueuer {
if strings.TrimSpace(url) == "" {
panic("worker equeuer: needs a non-empty url")
}
return &Enqueuer{
broker: broker.NewBroker(url),
}
}
// Enqueue will enqueue the specified message for job queue.
func (e *Enqueuer) Enqueue(queueName string, message proto.Message) error {
return e.broker.Enqueue(queueName, makeIdentifier(), message)
}
// EnqueueIn enqueues a message in the scheduled job queue for execution secondsFromNow seconds.
func (e *Enqueuer) EnqueueIn(name string, message proto.Message,
secondsFromNow int64) (string, error) {
return e.broker.EnqueueIn(name, makeIdentifier(), message, secondsFromNow)
}