You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.1 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
12 years ago
11 years ago
12 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. Gearman-Go
  2. ==========
  3. [![Build Status](https://travis-ci.org/mikespook/gearman-go.png?branch=master)](https://travis-ci.org/mikespook/gearman-go)
  4. This module is a [Gearman](http://gearman.org/) API for the [Go Programming Language](http://golang.org).
  5. The protocols were written in pure Go. It contains two sub-packages:
  6. The client package is used for sending jobs to the Gearman job server,
  7. and getting responses from the server.
  8. "github.com/mikespook/gearman-go/client"
  9. The worker package will help developers in developing Gearman worker
  10. service easily.
  11. "github.com/mikespook/gearman-go/worker"
  12. Install
  13. =======
  14. Install the client package:
  15. > $ go get github.com/mikespook/gearman-go/client
  16. Install the worker package:
  17. > $ go get github.com/mikespook/gearman-go/worker
  18. Both of them:
  19. > $ go get github.com/mikespook/gearman-go
  20. Usage
  21. =====
  22. ## Worker
  23. w := worker.New(worker.Unlimited)
  24. w.ErrHandler = func(e error) {
  25. log.Println(e)
  26. }
  27. w.AddServer("127.0.0.1:4730")
  28. w.AddFunc("ToUpper", ToUpper, worker.Immediately)
  29. w.AddFunc("ToUpperTimeOut5", ToUpper, 5)
  30. if err := w.Ready(); err != nil {
  31. log.Fatal(err)
  32. return
  33. }
  34. go w.Work()
  35. ## Client
  36. // ...
  37. c, err := client.New("tcp4", "127.0.0.1:4730")
  38. // ... error handling
  39. defer c.Close()
  40. c.ErrorHandler = func(e error) {
  41. log.Println(e)
  42. }
  43. echo := []byte("Hello\x00 world")
  44. echomsg, err := c.Echo(echo)
  45. // ... error handling
  46. log.Println(string(echomsg))
  47. jobHandler := func(job *client.Job) {
  48. log.Printf("%s", job.Data)
  49. }
  50. handle, err := c.Do("ToUpper", echo, client.JOB_NORMAL, jobHandler)
  51. // ...
  52. Branches
  53. ========
  54. Version 0.x means: _It is far far away from stable._
  55. __Use at your own risk!__
  56. * master current usable version
  57. * 0.2-dev Refactoring a lot of things
  58. * 0.1-testing Old API and some known issues, eg. [issue-14](https://github.com/mikespook/gearman-go/issues/14)
  59. Authors
  60. =======
  61. * Xing Xing <mikespook@gmail.com> [Blog](http://mikespook.com) [@Twitter](http://twitter.com/mikespook)
  62. Open Source - MIT Software License
  63. ==================================
  64. Copyright (c) 2012 Xing Xing
  65. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  66. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  67. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.