2011-05-20 17:38:10 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2012-05-22 20:05:39 +08:00
|
|
|
"sync"
|
|
|
|
"bitbucket.org/mikespook/gearman-go/client"
|
2011-05-20 17:38:10 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2012-05-22 20:05:39 +08:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
2012-05-23 15:22:29 +08:00
|
|
|
c, err := client.New("127.0.0.1:4730")
|
2012-05-22 20:05:39 +08:00
|
|
|
if err != nil {
|
2011-10-09 17:53:55 +08:00
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2012-05-22 20:05:39 +08:00
|
|
|
defer c.Close()
|
2011-09-05 12:41:53 +08:00
|
|
|
echo := []byte("Hello\x00 world")
|
2012-05-22 20:05:39 +08:00
|
|
|
c.JobHandler = func(job *client.Job) error {
|
2012-05-23 15:22:29 +08:00
|
|
|
log.Printf("%s", job.Data)
|
2012-05-22 20:05:39 +08:00
|
|
|
wg.Done()
|
|
|
|
return nil
|
2011-05-21 21:11:29 +08:00
|
|
|
}
|
|
|
|
|
2012-05-23 15:22:29 +08:00
|
|
|
c.ErrHandler = func(e error) {
|
|
|
|
log.Println(e)
|
|
|
|
panic(e)
|
|
|
|
}
|
2012-05-22 20:05:39 +08:00
|
|
|
wg.Add(1)
|
|
|
|
c.Echo(echo)
|
2012-05-23 15:22:29 +08:00
|
|
|
wg.Add(1)
|
|
|
|
handle, err := c.Do("ToUpper", echo, client.JOB_NORMAL)
|
2011-05-20 17:38:10 +08:00
|
|
|
if err != nil {
|
2011-10-09 17:53:55 +08:00
|
|
|
log.Fatalln(err)
|
2011-05-21 12:32:44 +08:00
|
|
|
} else {
|
|
|
|
log.Println(handle)
|
2011-05-20 17:38:10 +08:00
|
|
|
}
|
2011-05-24 13:20:22 +08:00
|
|
|
|
2012-05-22 20:05:39 +08:00
|
|
|
c.StatusHandler = func(handle string, known, running bool, numerator, denominator uint64) {
|
|
|
|
log.Printf("%s: %b, %b, %d, %d", handle, known, running, numerator, denominator)
|
|
|
|
wg.Done()
|
2011-05-20 17:38:10 +08:00
|
|
|
}
|
2012-05-22 20:05:39 +08:00
|
|
|
wg.Add(1)
|
|
|
|
c.Status(handle)
|
2012-05-23 15:22:29 +08:00
|
|
|
|
2012-05-22 20:05:39 +08:00
|
|
|
wg.Wait()
|
2011-05-20 17:38:10 +08:00
|
|
|
}
|