update examples

--HG--
branch : dev
This commit is contained in:
mikespook 2012-08-30 17:56:10 +08:00
parent b7ee1d68f5
commit adf3729627
2 changed files with 23 additions and 5 deletions

View File

@ -15,7 +15,13 @@ def main():
completed_job_request = client.submit_job("ToUpper", "arbitrary binary data") completed_job_request = client.submit_job("ToUpper", "arbitrary binary data")
check_request_status(completed_job_request) check_request_status(completed_job_request)
if __name__ == '__main__': completed_job_request = client.submit_job("ToUpperTimeOut5", "arbitrary binary data")
for i in range(2): check_request_status(completed_job_request)
main()
completed_job_request = client.submit_job("ToUpperTimeOut20", "arbitrary binary data")
check_request_status(completed_job_request)
if __name__ == '__main__':
main()

View File

@ -3,18 +3,29 @@ package main
import ( import (
"os" "os"
"log" "log"
"time"
"strings" "strings"
"bitbucket.org/mikespook/golib/signal" "bitbucket.org/mikespook/golib/signal"
"bitbucket.org/mikespook/gearman-go/worker" "bitbucket.org/mikespook/gearman-go/worker"
) )
func ToUpper(job *worker.Job) ([]byte, error) { 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) job.Handle, job.UniqueId, job.Data)
data := []byte(strings.ToUpper(string(job.Data))) data := []byte(strings.ToUpper(string(job.Data)))
return data, nil 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() { func main() {
log.Println("Starting ...") log.Println("Starting ...")
defer log.Println("Shutdown complete!") defer log.Println("Shutdown complete!")
@ -39,7 +50,8 @@ func main() {
} }
w.AddServer("127.0.0.1:4730") w.AddServer("127.0.0.1:4730")
w.AddFunc("ToUpper", ToUpper, 0) w.AddFunc("ToUpper", ToUpper, 0)
//w.AddFunc("ToUpperTimeOut5", ToUpper, 5) w.AddFunc("ToUpperTimeOut5", ToUpperDelay10, 5)
w.AddFunc("ToUpperTimeOut20", ToUpperDelay10, 20)
go w.Work() go w.Work()
sh := signal.NewHandler() sh := signal.NewHandler()
sh.Bind(os.Interrupt, func() bool {return true}) sh.Bind(os.Interrupt, func() bool {return true})