forked from kdar/goqless
-
Notifications
You must be signed in to change notification settings - Fork 3
/
goqless_test.go
94 lines (78 loc) · 1.78 KB
/
goqless_test.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package goqless
import (
"fmt"
"github.com/garyburd/redigo/redis"
"sync"
"testing"
"time"
)
// func TestRandom(t *testing.T) {
// c, err := Dial("", "6379")
// if err != nil {
// panic(err)
// }
// defer c.Close()
// // fmt.Println(c.Completed(0, 9999))
// tagged, err := c.Tagged("__callback", 0, 0)
// if err != nil {
// fmt.Println(err)
// }
// if err == nil {
// job := NewJob(c)
// for n, j := range tagged.Jobs {
// fmt.Println(n, j)
// job.Jid = j
// fmt.Println(job.Untag("__callback"))
// }
// }
// }
func TestGoqless(t *testing.T) {
var wg sync.WaitGroup
c, err := Dial("", "6379")
if err != nil {
panic(err)
}
defer c.Close()
e := c.Events()
ch, err := e.Listen()
if err != nil {
panic(err)
}
go func() {
wg.Add(1)
defer wg.Done()
for {
if val, ok := <-ch; ok {
switch v := (val).(type) {
case redis.Message:
fmt.Printf("WATCH: %s: message: %s\n", v.Channel, v.Data)
case redis.Subscription:
fmt.Printf("WATCH: %s: %s %d\n", v.Channel, v.Kind, v.Count)
case error:
return
}
} else {
return
}
}
}()
jid := generateJID()
c.Track(jid)
q := c.Queue("goqless_testing_queue")
putreply, err := q.Put(jid, "dunno", `{"hey": "there"}`, -1, -1, []string{"__callback"}, -1, []string{})
fmt.Println("Put:", putreply, err)
//fmt.Println(q.Recur(jid, "dunno", `{"hey": "there"}`, 5, 0, 0, []string{}, 1))
for {
jobs, err := q.Pop(1)
if err != nil {
panic(err)
}
if len(jobs) > 0 {
jobs[0].Data = map[string]interface{}{"idid": "id"}
fmt.Println(jobs[0].Complete())
}
time.Sleep(3 * time.Second)
fmt.Println(c.GetJob(jid))
}
wg.Wait()
}