gearman-go
gearman-go copied to clipboard
Worker dies after 1 request (cant use as a daemon)
Example code
package main
import
(
"github.com/mikespook/gearman-go/worker"
"log"
)
func ToUpper(job worker.Job) ([]byte, error) {
log.Printf("ToUpper: Data=[%s]\n", job.Data())
job.SendData(job.Data())
job.UpdateStatus(1, 1)
return nil, nil
}
func main() {
log.Println("Starting ...")
defer log.Println("Shutdown complete!")
w := worker.New( worker.Unlimited )
defer w.Close()
w.ErrorHandler = func(e error) {
log.Fatal(e)
return
}
w.JobHandler = func(job worker.Job) error {
log.Printf("Data=%s\n", job.Data())
return nil
}
w.AddServer("tcp4", "127.0.0.1:4730")
w.AddFunc("ToUpper", ToUpper, worker.Unlimited)
if err := w.Ready(); err != nil {
log.Fatal(err)
return
}
w.Work()
}
console:
2014/10/01 10:17:09 Starting ...
2014/10/01 10:17:12 ToUpper: Data=[hello world]
2014/10/01 10:17:12 EOF
exit status 1
Could you show me the version of gearmand and OS environment and the client code?
Hello.
CentOS 6.5 Final x86_64
Name: libgearman Arch: x86_64 Version: 1.1.8 Release: 2.el6
Name: gearmand Arch: x86_64 Version: 1.1.8 Release: 2.el6
No problems with php and python, problems only with this extention :(
Client code included to server code
func ToUpper(job worker.Job) ([]byte, error) {
log.Printf("ToUpper: Data=[%s]\n", job.Data())
job.SendData(job.Data())
job.UpdateStatus(1, 1)
return nil, nil
}
this function used to process gearman data.