From adf3729627af78b0986a861a8788a2a093dc6dac Mon Sep 17 00:00:00 2001 From: mikespook Date: Thu, 30 Aug 2012 17:56:10 +0800 Subject: [PATCH] update examples --HG-- branch : dev --- example/py/client.py | 12 +++++++++--- example/worker.go | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/example/py/client.py b/example/py/client.py index d40551e..9f2f2e1 100755 --- a/example/py/client.py +++ b/example/py/client.py @@ -15,7 +15,13 @@ def main(): completed_job_request = client.submit_job("ToUpper", "arbitrary binary data") check_request_status(completed_job_request) -if __name__ == '__main__': - for i in range(2): - main() + completed_job_request = client.submit_job("ToUpperTimeOut5", "arbitrary binary data") + check_request_status(completed_job_request) + + completed_job_request = client.submit_job("ToUpperTimeOut20", "arbitrary binary data") + check_request_status(completed_job_request) + + +if __name__ == '__main__': + main() diff --git a/example/worker.go b/example/worker.go index a747584..6e06ca4 100644 --- a/example/worker.go +++ b/example/worker.go @@ -3,18 +3,29 @@ package main import ( "os" "log" + "time" "strings" "bitbucket.org/mikespook/golib/signal" "bitbucket.org/mikespook/gearman-go/worker" ) func ToUpper(job *worker.Job) ([]byte, error) { - log.Printf("ToUpper -- Handle=[%s]; UID=[%s], Data=[%s]\n", + log.Printf("ToUpper: Handle=[%s]; UID=[%s], Data=[%s]\n", job.Handle, job.UniqueId, job.Data) data := []byte(strings.ToUpper(string(job.Data))) return data, nil } +func ToUpperDelay10(job *worker.Job) ([]byte, error) { + log.Printf("ToUpperDelay10: Handle=[%s]; UID=[%s], Data=[%s]\n", + job.Handle, job.UniqueId, job.Data) + time.Sleep(10 * time.Second) + data := []byte(strings.ToUpper(string(job.Data))) + return data, nil +} + + + func main() { log.Println("Starting ...") defer log.Println("Shutdown complete!") @@ -39,7 +50,8 @@ func main() { } w.AddServer("127.0.0.1:4730") w.AddFunc("ToUpper", ToUpper, 0) - //w.AddFunc("ToUpperTimeOut5", ToUpper, 5) + w.AddFunc("ToUpperTimeOut5", ToUpperDelay10, 5) + w.AddFunc("ToUpperTimeOut20", ToUpperDelay10, 20) go w.Work() sh := signal.NewHandler() sh.Bind(os.Interrupt, func() bool {return true})