-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More work. Not exactly sure if everything works right or not.
- Loading branch information
Kevin Darlington
committed
Mar 3, 2013
1 parent
606385f
commit a77a673
Showing
7 changed files
with
350 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,67 @@ | ||
package goqless | ||
|
||
import ( | ||
"fmt" | ||
// "github.com/garyburd/redigo/redis" | ||
// "time" | ||
) | ||
// import ( | ||
// "fmt" | ||
// // "github.com/garyburd/redigo/redis" | ||
// // "time" | ||
// ) | ||
|
||
func ExampleGoqless_1() { | ||
c, err := Dial("", "6379") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer c.Close() | ||
// func ExampleGoqless_1() { | ||
// c, err := Dial("", "6379") | ||
// if err != nil { | ||
// panic(err) | ||
// } | ||
// defer c.Close() | ||
|
||
jid := "f5b66400bf027c191ddb80a85785b03eb9765456" | ||
c.Track(jid) | ||
q := c.Queue("goqless_testing_queue") | ||
// jid := "f5b66400bf027c191ddb80a85785b03eb9765456" | ||
// c.Track(jid) | ||
// q := c.Queue("goqless_testing_queue") | ||
|
||
putreply, err := q.Put(jid, "dunno", `{"hey": "there"}`, -1, -1, []string{}, -1, []string{}) | ||
fmt.Println("Put:", putreply, err) | ||
//fmt.Println(q.Recur(jid, "dunno", `{"hey": "there"}`, 5, 0, 0, []string{}, 1)) | ||
// putreply, err := q.Put(jid, "dunno", `{"hey": "there"}`, -1, -1, []string{}, -1, []string{}) | ||
// fmt.Println("Put:", putreply, err) | ||
// //fmt.Println(q.Recur(jid, "dunno", `{"hey": "there"}`, 5, 0, 0, []string{}, 1)) | ||
|
||
jobs, err := q.Pop(1) | ||
fmt.Printf("Pop: %s %s %v\n", jobs[0].Queue, jobs[0].Data, err) | ||
fmt.Print("Complete: ") | ||
fmt.Println(jobs[0].Complete()) | ||
// jobs, err := q.Pop(1) | ||
// fmt.Printf("Pop: %s %s %v\n", jobs[0].Queue, jobs[0].Data, err) | ||
// fmt.Print("Complete: ") | ||
// fmt.Println(jobs[0].Complete()) | ||
|
||
//wg.Wait() | ||
// //wg.Wait() | ||
|
||
// Output: | ||
// Put: f5b66400bf027c191ddb80a85785b03eb9765456 <nil> | ||
// Pop: goqless_testing_queue map[hey:there] <nil> | ||
// Complete: complete <nil> | ||
} | ||
// // Output: | ||
// // Put: f5b66400bf027c191ddb80a85785b03eb9765456 <nil> | ||
// // Pop: goqless_testing_queue map[hey:there] <nil> | ||
// // Complete: complete <nil> | ||
// } | ||
|
||
func ExampleGoqless_2() { | ||
c, err := Dial("", "6379") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer c.Close() | ||
// func ExampleGoqless_2() { | ||
// c, err := Dial("", "6379") | ||
// if err != nil { | ||
// panic(err) | ||
// } | ||
// defer c.Close() | ||
|
||
jid := "f5b66400bf027c191ddb80a85785b03eb9765457" | ||
c.Track(jid) | ||
q := c.Queue("goqless_testing_queue") | ||
// jid := "f5b66400bf027c191ddb80a85785b03eb9765457" | ||
// c.Track(jid) | ||
// q := c.Queue("goqless_testing_queue") | ||
|
||
data := struct { | ||
Str string | ||
}{ | ||
"a string", | ||
} | ||
// data := struct { | ||
// Str string | ||
// }{ | ||
// "a string", | ||
// } | ||
|
||
putreply, err := q.Put(jid, "dunno", data, -1, -1, []string{}, -1, []string{}) | ||
fmt.Println("Put:", putreply, err) | ||
//fmt.Println(q.Recur(jid, "dunno", `{"hey": "there"}`, 5, 0, 0, []string{}, 1)) | ||
// putreply, err := q.Put(jid, "dunno", data, -1, -1, []string{}, -1, []string{}) | ||
// fmt.Println("Put:", putreply, err) | ||
// //fmt.Println(q.Recur(jid, "dunno", `{"hey": "there"}`, 5, 0, 0, []string{}, 1)) | ||
|
||
jobs, err := q.Pop(1) | ||
fmt.Printf("Pop: %s %v %v\n", jobs[0].Queue, jobs[0].Data, err) | ||
fmt.Print("Fail: ") | ||
fmt.Println(jobs[0].Fail("justbecause", "i said so")) | ||
// jobs, err := q.Pop(1) | ||
// fmt.Printf("Pop: %s %v %v\n", jobs[0].Queue, jobs[0].Data, err) | ||
// fmt.Print("Fail: ") | ||
// fmt.Println(jobs[0].Fail("justbecause", "i said so")) | ||
|
||
// Output: | ||
// Put: f5b66400bf027c191ddb80a85785b03eb9765457 <nil> | ||
// Pop: goqless_testing_queue map[Str:a string] <nil> | ||
// Fail: true <nil> | ||
} | ||
// // Output: | ||
// // Put: f5b66400bf027c191ddb80a85785b03eb9765457 <nil> | ||
// // Pop: goqless_testing_queue map[Str:a string] <nil> | ||
// // Fail: true <nil> | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,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{}, -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 { | ||
// fmt.Println(jobs[0].Complete()) | ||
// } | ||
// time.Sleep(3 * time.Second) | ||
// } | ||
|
||
// wg.Wait() | ||
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() | ||
} |
Oops, something went wrong.