2011-05-18 20:24:59 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2012-05-24 16:49:35 +08:00
|
|
|
"os"
|
2012-03-26 13:32:59 +08:00
|
|
|
"log"
|
|
|
|
"strings"
|
2012-05-24 16:49:35 +08:00
|
|
|
"bitbucket.org/mikespook/golib/signal"
|
|
|
|
"bitbucket.org/mikespook/gearman-go/worker"
|
2011-05-18 20:24:59 +08:00
|
|
|
)
|
|
|
|
|
2012-05-23 17:45:52 +08:00
|
|
|
func ToUpper(job *worker.Job) ([]byte, error) {
|
2012-05-24 16:49:35 +08:00
|
|
|
log.Printf("Handle=[%s]; UID=[%s], Data=[%s]\n",
|
|
|
|
job.Handle, job.UniqueId, job.Data)
|
2012-03-26 13:32:59 +08:00
|
|
|
data := []byte(strings.ToUpper(string(job.Data)))
|
|
|
|
return data, nil
|
2011-05-18 20:24:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2012-05-24 16:49:35 +08:00
|
|
|
log.Println("Starting ...")
|
|
|
|
defer log.Println("Shutdown complete!")
|
2012-05-23 17:45:52 +08:00
|
|
|
w := worker.New(worker.Unlimited)
|
|
|
|
w.ErrHandler = func(e error) {
|
2012-05-10 21:25:33 +08:00
|
|
|
log.Println(e)
|
|
|
|
}
|
2012-05-24 16:49:35 +08:00
|
|
|
w.JobHandler = func(job *worker.Job) error {
|
|
|
|
log.Printf("H=%s, UID=%s, Data=%s\n", job.Handle,
|
|
|
|
job.UniqueId, job.Data)
|
|
|
|
return nil
|
|
|
|
}
|
2012-03-26 13:32:59 +08:00
|
|
|
w.AddServer("127.0.0.1:4730")
|
2012-05-24 16:49:35 +08:00
|
|
|
w.AddFunc("ToUpper", ToUpper, 0)
|
|
|
|
//w.AddFunc("ToUpperTimeOut5", ToUpper, 5)
|
|
|
|
go w.Work()
|
|
|
|
sh := signal.NewHandler()
|
|
|
|
sh.Bind(os.Interrupt, func() bool {return true})
|
|
|
|
sh.Loop()
|
2011-05-18 20:24:59 +08:00
|
|
|
}
|