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"
|
|
|
|
"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
|
|
|
|
|
|
|
|
c, err := client.New("tcp4", "127.0.0.1:4730")
|
|
|
|
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 {
|
|
|
|
log.Printf("%V", job)
|
|
|
|
wg.Done()
|
|
|
|
return nil
|
2011-05-21 21:11:29 +08:00
|
|
|
}
|
|
|
|
|
2012-05-22 20:05:39 +08:00
|
|
|
wg.Add(1)
|
|
|
|
c.Echo(echo)
|
|
|
|
|
|
|
|
handle, err := c.Do("ToUpper", echo, gearman.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)
|
|
|
|
wg.Wait()
|
2011-05-20 17:38:10 +08:00
|
|
|
}
|