gearman-go icon indicating copy to clipboard operation
gearman-go copied to clipboard

Worker dies after 1 request (cant use as a daemon)

Open ergoz opened this issue 11 years ago • 3 comments

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

ergoz avatar Oct 01 '14 06:10 ergoz

Could you show me the version of gearmand and OS environment and the client code?

mikespook avatar Oct 08 '14 01:10 mikespook

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 :(

ergoz avatar Oct 08 '14 06:10 ergoz

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.

ergoz avatar Nov 05 '14 10:11 ergoz