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.2 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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. Gearman-Go
  2. ==========
  3. This module is a [Gearman](http://gearman.org/) API for the [Go Programming Language](http://golang.org).
  4. The protocols were written in pure Go. It contains two sub-packages:
  5. The client package is used for sending jobs to the Gearman job server,
  6. and getting responses from the server.
  7. "github.com/mikespook/gearman-go/client"
  8. The worker package will help developers in developing Gearman worker
  9. service easily.
  10. "github.com/mikespook/gearman-go/worker"
  11. [![Build Status](https://travis-ci.org/mikespook/gearman-go.png?branch=master)](https://travis-ci.org/mikespook/gearman-go)
  12. [![GoDoc](https://godoc.org/github.com/mikespook/gearman-go?status.png)](https://godoc.org/github.com/mikespook/gearman-go)
  13. Install
  14. =======
  15. Install the client package:
  16. > $ go get github.com/mikespook/gearman-go/client
  17. Install the worker package:
  18. > $ go get github.com/mikespook/gearman-go/worker
  19. Both of them:
  20. > $ go get github.com/mikespook/gearman-go
  21. Usage
  22. =====
  23. ## Worker
  24. w := worker.New(worker.Unlimited)
  25. w.ErrHandler = func(e error) {
  26. log.Println(e)
  27. }
  28. w.AddServer("127.0.0.1:4730")
  29. w.AddFunc("ToUpper", ToUpper, worker.Immediately)
  30. w.AddFunc("ToUpperTimeOut5", ToUpper, 5)
  31. if err := w.Ready(); err != nil {
  32. log.Fatal(err)
  33. return
  34. }
  35. go w.Work()
  36. ## Client
  37. // ...
  38. c, err := client.New("tcp4", "127.0.0.1:4730")
  39. // ... error handling
  40. defer c.Close()
  41. c.ErrorHandler = func(e error) {
  42. log.Println(e)
  43. }
  44. echo := []byte("Hello\x00 world")
  45. echomsg, err := c.Echo(echo)
  46. // ... error handling
  47. log.Println(string(echomsg))
  48. jobHandler := func(job *client.Job) {
  49. log.Printf("%s", job.Data)
  50. }
  51. handle, err := c.Do("ToUpper", echo, client.JOB_NORMAL, jobHandler)
  52. // ...
  53. Branches
  54. ========
  55. Version 0.x means: _It is far far away from stable._
  56. __Use at your own risk!__
  57. * master current usable version
  58. * 0.2-dev Refactoring a lot of things
  59. * 0.1-testing Old API and some known issues, eg. [issue-14](https://github.com/mikespook/gearman-go/issues/14)
  60. Authors
  61. =======
  62. * Xing Xing <mikespook@gmail.com> [Blog](http://mikespook.com) [@Twitter](http://twitter.com/mikespook)
  63. Open Source - MIT Software License
  64. ==================================
  65. Copyright (c) 2012 Xing Xing
  66. 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:
  67. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  68. 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.