gearman-go/example/client.go
mikespook e0c1537e8e code refactoring, upgrade to GO1 RC2
--HG--
rename : README => README.md
rename : src/gearman/client.go => gearman/client/client.go
rename : src/gearman/client_test.go => gearman/client/client_test.go
rename : src/gearman/clientjob.go => gearman/client/clientjob.go
rename : src/gearman/gearman.go => gearman/gearman.go
rename : src/gearman/jobagent.go => gearman/worker/jobagent.go
rename : src/gearman/worker.go => gearman/worker/worker.go
rename : src/gearman/worker_test.go => gearman/worker/worker_test.go
rename : src/gearman/workerjob.go => gearman/worker/workerjob.go
2012-03-26 13:32:59 +08:00

47 lines
1.1 KiB
Go

package main
import (
"bitbucket.org/mikespook/gearman-go/gearman"
"bitbucket.org/mikespook/gearman-go/gearman/client"
"log"
)
func main() {
client := client.NewClient()
defer client.Close()
if err := client.AddServer("127.0.0.1:4730"); err != nil {
log.Fatalln(err)
}
echo := []byte("Hello\x00 world")
if data, err := client.Echo(echo); err != nil {
log.Fatalln(string(data))
}
handle, err := client.Do("ToUpper", echo, gearman.JOB_NORMAL)
if err != nil {
log.Fatalln(err)
} else {
log.Println(handle)
job := <-client.JobQueue
if data, err := job.Result(); err != nil {
log.Fatalln(err)
} else {
log.Println(string(data))
}
}
known, running, numerator, denominator, err := client.Status(handle)
if err != nil {
log.Fatalln(err)
}
if !known {
log.Println("Unknown")
}
if running {
log.Printf("%g%%\n", float32(numerator)*100/float32(denominator))
} else {
log.Println("Not running")
}
}