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 2.7 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
12 years ago
11 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. // Limit number of concurrent jobs execution. Use worker.Unlimited (0) if you want no limitation.
  25. w := worker.New(worker.OneByOne)
  26. w.ErrHandler = func(e error) {
  27. log.Println(e)
  28. }
  29. w.AddServer("127.0.0.1:4730")
  30. // Use worker.Unlimited (0) if you want no timeout
  31. w.AddFunc("ToUpper", ToUpper, worker.Unlimited)
  32. // This will give a timeout of 5 seconds
  33. w.AddFunc("ToUpperTimeOut5", ToUpper, 5)
  34. if err := w.Ready(); err != nil {
  35. log.Fatal(err)
  36. return
  37. }
  38. go w.Work()
  39. ## Client
  40. // ...
  41. c, err := client.New("tcp4", "127.0.0.1:4730")
  42. // ... error handling
  43. defer c.Close()
  44. c.ErrorHandler = func(e error) {
  45. log.Println(e)
  46. }
  47. echo := []byte("Hello\x00 world")
  48. echomsg, err := c.Echo(echo)
  49. // ... error handling
  50. log.Println(string(echomsg))
  51. jobHandler := func(job *client.Job) {
  52. log.Printf("%s", job.Data)
  53. }
  54. handle, err := c.Do("ToUpper", echo, client.JOB_NORMAL, jobHandler)
  55. // ...
  56. Branches
  57. ========
  58. Version 0.x means: _It is far far away from stable._
  59. __Use at your own risk!__
  60. * master current usable version
  61. * 0.2-dev Refactoring a lot of things
  62. * 0.1-testing Old API and some known issues, eg. [issue-14](https://github.com/mikespook/gearman-go/issues/14)
  63. Contributors
  64. ============
  65. (_Alphabetic order_)
  66. * [Alex Zylman](https://github.com/azylman)
  67. * [Ingo Oeser](https://github.com/nightlyone)
  68. * [jake](https://github.com/jbaikge)
  69. * [Jonathan Wills](https://github.com/runningwild)
  70. * [miraclesu](https://github.com/miraclesu)
  71. * [Paul Mach](https://github.com/paulmach)
  72. * [Sam Grimee](https://github.com/sgrimee)
  73. * suchj
  74. * [Xing Xing](http://mikespook.com) <mikespook@gmail.com> [@Twitter](http://twitter.com/mikespook)
  75. Open Source - MIT Software License
  76. ==================================
  77. See LICENSE.