2011-05-20 17:38:10 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2012-03-26 13:32:59 +08:00
|
|
|
"bitbucket.org/mikespook/gearman-go/gearman"
|
|
|
|
"bitbucket.org/mikespook/gearman-go/gearman/client"
|
2011-05-20 17:38:10 +08:00
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2012-03-27 22:48:03 +08:00
|
|
|
client := client.New()
|
2011-05-20 17:38:10 +08:00
|
|
|
defer client.Close()
|
2011-10-09 17:53:55 +08:00
|
|
|
if err := client.AddServer("127.0.0.1:4730"); err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2011-09-05 12:41:53 +08:00
|
|
|
echo := []byte("Hello\x00 world")
|
2011-05-21 21:11:29 +08:00
|
|
|
|
|
|
|
if data, err := client.Echo(echo); err != nil {
|
2011-10-09 17:53:55 +08:00
|
|
|
log.Fatalln(string(data))
|
2011-05-21 21:11:29 +08:00
|
|
|
}
|
|
|
|
|
2011-05-21 12:32:44 +08:00
|
|
|
handle, err := client.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-12-28 17:59:44 +08:00
|
|
|
job := <-client.JobQueue
|
2011-05-21 21:11:29 +08:00
|
|
|
if data, err := job.Result(); err != nil {
|
2011-10-09 17:53:55 +08:00
|
|
|
log.Fatalln(err)
|
2011-05-21 21:11:29 +08:00
|
|
|
} else {
|
|
|
|
log.Println(string(data))
|
2011-12-28 17:59:44 +08:00
|
|
|
}
|
2011-05-20 17:38:10 +08:00
|
|
|
}
|
2011-05-24 13:20:22 +08:00
|
|
|
|
2011-05-20 17:38:10 +08:00
|
|
|
known, running, numerator, denominator, err := client.Status(handle)
|
|
|
|
if err != nil {
|
2011-10-09 17:53:55 +08:00
|
|
|
log.Fatalln(err)
|
2011-05-20 17:38:10 +08:00
|
|
|
}
|
|
|
|
if !known {
|
|
|
|
log.Println("Unknown")
|
|
|
|
}
|
|
|
|
if running {
|
2011-05-24 13:20:22 +08:00
|
|
|
log.Printf("%g%%\n", float32(numerator)*100/float32(denominator))
|
2011-05-20 17:38:10 +08:00
|
|
|
} else {
|
|
|
|
log.Println("Not running")
|
|
|
|
}
|
|
|
|
}
|