gearman-go/README.md

106 lines
2.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
// Limit number of concurrent jobs execution. Use worker.Unlimited (0) if you want no limitation.
w := worker.New(worker.OneByOne)
2012-05-24 19:57:06 +08:00
w.ErrHandler = func(e error) {
log.Println(e)
}
w.AddServer("127.0.0.1:4730")
// Use worker.Unlimited (0) if you want no timeout
w.AddFunc("ToUpper", ToUpper, worker.Unlimited)
// This will give a timeout of 5 seconds
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
==================================
2012-03-26 14:10:15 +08:00
See LICENSE.