gearman-go/example/client/client.go

49 lines
920 B
Go
Raw Normal View History

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"
)
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()
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()
jobHandler := func(resp *client.Response) {
log.Printf("%s", resp.Data)
2013-12-25 17:01:42 +08:00
wg.Done()
}
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)
2013-12-25 17:01:42 +08:00
wg.Wait()
}