2011-05-20 17:38:10 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2012-05-22 20:05:39 +08:00
|
|
|
"sync"
|
2013-04-23 16:58:06 +08:00
|
|
|
"time"
|
2012-12-21 11:11:37 +08:00
|
|
|
"github.com/mikespook/gearman-go/client"
|
2011-05-20 17:38:10 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2012-05-22 20:05:39 +08:00
|
|
|
var wg sync.WaitGroup
|
2013-02-28 13:28:48 +08:00
|
|
|
// 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()
|
2012-05-22 20:05:39 +08:00
|
|
|
|
2012-05-23 15:22:29 +08:00
|
|
|
c, err := client.New("127.0.0.1:4730")
|
2012-05-22 20:05:39 +08:00
|
|
|
if err != nil {
|
2011-10-09 17:53:55 +08:00
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2012-05-22 20:05:39 +08:00
|
|
|
defer c.Close()
|
2012-05-23 15:22:29 +08:00
|
|
|
c.ErrHandler = func(e error) {
|
|
|
|
log.Println(e)
|
|
|
|
}
|
2013-02-28 13:28:48 +08:00
|
|
|
echo := []byte("Hello\x00 world")
|
2012-05-22 20:05:39 +08:00
|
|
|
wg.Add(1)
|
2013-04-23 16:58:06 +08:00
|
|
|
log.Println(string(c.Echo(echo)))
|
|
|
|
wg.Done()
|
2013-02-28 13:28:48 +08:00
|
|
|
jobHandler := func(job *client.Job) {
|
|
|
|
log.Printf("%s", job.Data)
|
2012-05-22 20:05:39 +08:00
|
|
|
wg.Done()
|
2011-05-20 17:38:10 +08:00
|
|
|
}
|
2013-02-28 13:28:48 +08:00
|
|
|
handle := c.Do("ToUpper", echo, client.JOB_NORMAL, jobHandler)
|
2012-05-22 20:05:39 +08:00
|
|
|
wg.Add(1)
|
2013-04-23 16:58:06 +08:00
|
|
|
status, err := c.Status(handle, time.Second)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
log.Printf("%t", status)
|
2012-05-23 15:22:29 +08:00
|
|
|
|
2012-05-22 20:05:39 +08:00
|
|
|
wg.Wait()
|
2011-05-20 17:38:10 +08:00
|
|
|
}
|