gearman-go/example/client/client.go

49 lines
1.0 KiB
Go
Raw Normal View History

package main
import (
"log"
"sync"
2012-12-21 11:11:37 +08:00
"github.com/mikespook/gearman-go/client"
)
func main() {
var wg sync.WaitGroup
// Set the autoinc id generator
// You can write your own id generator
// by implementing IdGenerator interface.
2013-04-23 16:58:06 +08:00
// client.IdGen = client.NewAutoIncId()
2013-09-22 22:58:22 +08:00
c, err := client.New("tcp4", "127.0.0.1:4730")
if err != nil {
2011-10-09 17:53:55 +08:00
log.Fatalln(err)
}
defer c.Close()
2013-09-22 22:58:22 +08:00
c.ErrorHandler = func(e error) {
log.Println(e)
}
echo := []byte("Hello\x00 world")
wg.Add(1)
2013-09-22 22:58:22 +08:00
echomsg, err := c.Echo(echo)
2013-04-24 16:58:06 +08:00
if err != nil {
log.Fatalln(err)
}
log.Println(string(echomsg))
2013-04-23 16:58:06 +08:00
wg.Done()
2013-09-22 22:58:22 +08:00
jobHandler := func(job *client.Response) {
log.Printf("%s", job.Data)
wg.Done()
}
2013-09-22 22:58:22 +08:00
handle, err := c.Do("ToUpper", echo, client.JOB_NORMAL, jobHandler)
if err != nil {
log.Fatalln(err)
}
wg.Add(1)
2013-09-22 22:58:22 +08:00
status, err := c.Status(handle)
2013-04-23 16:58:06 +08:00
if err != nil {
log.Fatalln(err)
}
log.Printf("%t", status)
wg.Wait()
}