-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
60 lines (48 loc) · 1.13 KB
/
main.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
package gluttony
import (
"sync"
"github.com/Sirupsen/logrus"
"github.com/ethervoid/gluttony/connector"
"github.com/ethervoid/gluttony/consumer"
"github.com/ethervoid/gluttony/task"
)
type gluttony struct {
connData *connector.ConnectorData
taskFactory task.TaskFactory
}
func New(connData *connector.ConnectorData) *gluttony {
if len(connData.Queues) == 0 {
logrus.Fatal("You must pass at least one queue")
}
if connData.Host == "" {
logrus.Fatal("Host can't be empty")
}
if connData.Type == "" {
logrus.Fatal("Connector type can't be empty")
}
client := gluttony{}
client.connData = connData
return &client
}
func (gluttony *gluttony) RegisterJobsFactory(taskFactory task.TaskFactory) {
gluttony.taskFactory = taskFactory
}
func (gluttony *gluttony) Start(consumers int) {
var wg sync.WaitGroup
wg.Add(consumers)
for i := 0; i < consumers; i++ {
go func() {
consumer, err := consumer.New(
gluttony.connData,
gluttony.taskFactory,
)
if err != nil {
logrus.Fatal("Error trying to create consumer")
}
defer wg.Done()
defer consumer.Close()
consumer.Start()
}()
}
wg.Wait()
}