gearman-go/example/client.go

47 lines
953 B
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
c, err := client.New("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("%s", job.Data)
wg.Done()
return nil
}
c.ErrHandler = func(e error) {
log.Println(e)
panic(e)
}
wg.Add(1)
c.Echo(echo)
wg.Add(1)
handle, err := c.Do("ToUpper", echo, client.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()
}