gearman-go/example/client.go

43 lines
906 B
Go
Raw Normal View History

package main
import (
"log"
"sync"
"bitbucket.org/mikespook/gearman-go"
"bitbucket.org/mikespook/gearman-go/client"
)
func main() {
var wg sync.WaitGroup
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()
echo := []byte("Hello\x00 world")
c.JobHandler = func(job *client.Job) error {
log.Printf("%V", job)
wg.Done()
return nil
}
wg.Add(1)
c.Echo(echo)
handle, err := c.Do("ToUpper", echo, gearman.JOB_NORMAL)
if err != nil {
2011-10-09 17:53:55 +08:00
log.Fatalln(err)
} else {
log.Println(handle)
}
2011-05-24 13:20:22 +08:00
c.StatusHandler = func(handle string, known, running bool, numerator, denominator uint64) {
log.Printf("%s: %b, %b, %d, %d", handle, known, running, numerator, denominator)
wg.Done()
}
wg.Add(1)
c.Status(handle)
wg.Wait()
}