2011-05-20 17:38:10 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"gearman"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
client := gearman.NewClient()
|
|
|
|
defer client.Close()
|
|
|
|
client.AddServer("127.0.0.1:4730")
|
|
|
|
echo := []byte("Hello world")
|
2011-05-21 12:32:44 +08:00
|
|
|
/*
|
2011-05-20 17:38:10 +08:00
|
|
|
log.Println(echo)
|
|
|
|
log.Println(client.Echo(echo))
|
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 {
|
|
|
|
log.Println(err)
|
2011-05-21 12:32:44 +08:00
|
|
|
} else {
|
|
|
|
log.Println(handle)
|
|
|
|
log.Println(<-client.JobQueue)
|
2011-05-20 17:38:10 +08:00
|
|
|
}
|
2011-05-21 12:32:44 +08:00
|
|
|
/*
|
2011-05-20 17:38:10 +08:00
|
|
|
known, running, numerator, denominator, err := client.Status(handle)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
if !known {
|
|
|
|
log.Println("Unknown")
|
|
|
|
}
|
|
|
|
if running {
|
|
|
|
log.Printf("%g%%\n", float32(numerator) * 100 / float32(denominator))
|
|
|
|
} else {
|
|
|
|
log.Println("Not running")
|
|
|
|
}
|
|
|
|
log.Println("read")
|
|
|
|
if job, err := client.ReadJob(); err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
} else {
|
|
|
|
data, err := job.Result();
|
|
|
|
log.Println(err)
|
|
|
|
log.Println(data)
|
|
|
|
}
|
2011-05-21 12:32:44 +08:00
|
|
|
*/
|
2011-05-20 17:38:10 +08:00
|
|
|
}
|