7614c2678a
--HG-- branch : 0.1 rename : gearman/client/client.go => client/client.go rename : gearman/client/client_test.go => client/client_test.go rename : gearman/client/clientjob.go => client/job.go rename : gearman/gearman.go => common/gearman.go rename : gearman/worker/jobagent.go => worker/jobagent.go rename : gearman/worker/worker.go => worker/worker.go rename : gearman/worker/worker_test.go => worker/worker_test.go rename : gearman/worker/workerjob.go => worker/workerjob.go
43 lines
906 B
Go
43 lines
906 B
Go
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 {
|
|
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 {
|
|
log.Fatalln(err)
|
|
} else {
|
|
log.Println(handle)
|
|
}
|
|
|
|
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()
|
|
}
|