2011-05-20 17:38:10 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-12-24 14:39:04 +08:00
|
|
|
"github.com/mikespook/gearman-go/client"
|
2013-12-25 17:01:42 +08:00
|
|
|
"log"
|
|
|
|
"sync"
|
2011-05-20 17:38:10 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2013-12-25 17:01:42 +08:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
// Set the autoinc id generator
|
2013-12-24 14:39:04 +08:00
|
|
|
// You can write your own id generator
|
2013-12-25 17:01:42 +08:00
|
|
|
// by implementing IdGenerator interface.
|
|
|
|
// client.IdGen = client.NewAutoIncId()
|
2012-05-22 20:05:39 +08:00
|
|
|
|
2013-12-26 15:28:42 +08:00
|
|
|
c, err := client.New(client.Network, "127.0.0.1:4730")
|
2013-12-25 17:01:42 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
defer c.Close()
|
2013-12-24 14:39:04 +08:00
|
|
|
c.ErrorHandler = func(e error) {
|
2013-12-25 17:01:42 +08:00
|
|
|
log.Println(e)
|
|
|
|
}
|
|
|
|
echo := []byte("Hello\x00 world")
|
|
|
|
wg.Add(1)
|
2013-12-24 14:39:04 +08:00
|
|
|
echomsg, err := c.Echo(echo)
|
2013-09-22 22:58:22 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2013-12-25 17:01:42 +08:00
|
|
|
log.Println(string(echomsg))
|
|
|
|
wg.Done()
|
2013-12-26 15:28:42 +08:00
|
|
|
jobHandler := func(resp *client.Response) {
|
|
|
|
log.Printf("%s", resp.Data)
|
2013-12-25 17:01:42 +08:00
|
|
|
wg.Done()
|
|
|
|
}
|
2013-12-26 15:28:42 +08:00
|
|
|
handle, err := c.Do("ToUpper", echo, client.JobNormal, jobHandler)
|
2013-12-25 17:01:42 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
wg.Add(1)
|
2013-12-24 14:39:04 +08:00
|
|
|
status, err := c.Status(handle)
|
2013-12-25 17:01:42 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
log.Printf("%t", status)
|
2012-05-23 15:22:29 +08:00
|
|
|
|
2013-12-25 17:01:42 +08:00
|
|
|
wg.Wait()
|
2011-05-20 17:38:10 +08:00
|
|
|
}
|