gearman-go/README.md

109 lines
3.7 KiB
Markdown
Raw Normal View History

2012-12-21 10:59:43 +08:00
Gearman-Go
2012-12-21 10:51:15 +08:00
==========
2013-06-09 12:31:25 +08:00
2013-12-25 17:01:42 +08:00
This module is a [Gearman](http://gearman.org/) API for the [Go Programming Language](http://golang.org).
The protocols were written in pure Go. It contains two sub-packages:
The client package is used for sending jobs to the Gearman job server,
and getting responses from the server.
"github.com/mikespook/gearman-go/client"
The worker package will help developers in developing Gearman worker
service easily.
"github.com/mikespook/gearman-go/worker"
2013-12-26 16:02:30 +08:00
[![Build Status](https://travis-ci.org/mikespook/gearman-go.png?branch=master)](https://travis-ci.org/mikespook/gearman-go)
[![GoDoc](https://godoc.org/github.com/mikespook/gearman-go?status.png)](https://godoc.org/github.com/mikespook/gearman-go)
2012-12-21 11:11:37 +08:00
Install
=======
2012-05-24 19:57:06 +08:00
Install the client package:
2012-12-21 11:11:37 +08:00
> $ go get github.com/mikespook/gearman-go/client
2012-05-24 19:57:06 +08:00
Install the worker package:
2012-12-21 11:11:37 +08:00
> $ go get github.com/mikespook/gearman-go/worker
2013-12-25 17:01:42 +08:00
Both of them:
2012-12-21 11:11:37 +08:00
> $ go get github.com/mikespook/gearman-go
2012-12-21 11:11:37 +08:00
Usage
=====
## Worker
2012-05-24 19:57:06 +08:00
w := worker.New(worker.Unlimited)
w.ErrHandler = func(e error) {
log.Println(e)
}
w.AddServer("127.0.0.1:4730")
// this will give a timeout of 2 seconds. Use worker.Unlimited (0) if you want no timeout
w.AddFunc("ToUpper", ToUpper, worker.Immediately)
2012-05-24 19:57:06 +08:00
w.AddFunc("ToUpperTimeOut5", ToUpper, 5)
2013-12-24 14:39:04 +08:00
if err := w.Ready(); err != nil {
log.Fatal(err)
return
}
go w.Work()
## Client
2013-12-25 17:01:42 +08:00
// ...
c, err := client.New("tcp4", "127.0.0.1:4730")
// ... error handling
defer c.Close()
c.ErrorHandler = func(e error) {
2012-05-24 19:57:06 +08:00
log.Println(e)
}
2013-12-25 17:01:42 +08:00
echo := []byte("Hello\x00 world")
echomsg, err := c.Echo(echo)
// ... error handling
log.Println(string(echomsg))
2013-01-18 17:03:45 +08:00
jobHandler := func(job *client.Job) {
log.Printf("%s", job.Data)
}
2013-12-25 17:01:42 +08:00
handle, err := c.Do("ToUpper", echo, client.JOB_NORMAL, jobHandler)
// ...
2013-08-30 11:20:51 +08:00
Branches
========
Version 0.x means: _It is far far away from stable._
__Use at your own risk!__
* master current usable version
2013-12-25 17:01:42 +08:00
* 0.2-dev Refactoring a lot of things
* 0.1-testing Old API and some known issues, eg. [issue-14](https://github.com/mikespook/gearman-go/issues/14)
2013-08-30 11:20:51 +08:00
2014-01-15 10:04:41 +08:00
Contributors
============
(_Alphabetic order_)
* [Alex Zylman](https://github.com/azylman)
* [Ingo Oeser](https://github.com/nightlyone)
* [jake](https://github.com/jbaikge)
* [Jonathan Wills](https://github.com/runningwild)
* [miraclesu](https://github.com/miraclesu)
* [Paul Mach](https://github.com/paulmach)
* [Sam Grimee](https://github.com/sgrimee)
* suchj
* [Xing Xing](http://mikespook.com) <mikespook@gmail.com> [@Twitter](http://twitter.com/mikespook)
2012-03-26 14:10:15 +08:00
2012-12-21 11:11:37 +08:00
Open Source - MIT Software License
==================================
Copyright (c) 2012 Xing Xing
2012-03-26 14:10:15 +08:00
2012-12-21 11:11:37 +08:00
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:
2012-12-21 11:11:37 +08:00
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
2012-12-21 11:11:37 +08:00
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.