2012-03-26 13:32:59 +08:00
|
|
|
# Gearman API for golang
|
|
|
|
|
2012-05-24 19:57:06 +08:00
|
|
|
This package is a [Gearman](http://gearman.org/) API for [Golang](http://golang.org).
|
|
|
|
It was implemented a native protocol for both worker and client API.
|
2012-03-26 13:32:59 +08:00
|
|
|
|
2012-05-24 19:57:06 +08:00
|
|
|
Copyright 2012 Xing Xing <mikespook@gmail.com>
|
|
|
|
All rights reserved.
|
|
|
|
Use of this source code is governed by a MIT license that can be found
|
2012-03-26 14:10:15 +08:00
|
|
|
in the LICENSE file.
|
2012-03-26 13:32:59 +08:00
|
|
|
|
|
|
|
# INSTALL
|
|
|
|
|
2012-05-24 19:57:06 +08:00
|
|
|
Install the client package:
|
2012-03-26 13:32:59 +08:00
|
|
|
|
2012-05-24 16:56:36 +08:00
|
|
|
> $ go get bitbucket.org/mikespook/gearman-go/client
|
2012-03-26 13:32:59 +08:00
|
|
|
|
2012-05-24 19:57:06 +08:00
|
|
|
Install the worker package:
|
2012-03-26 13:32:59 +08:00
|
|
|
|
2012-05-24 16:56:36 +08:00
|
|
|
> $ go get bitbucket.org/mikespook/gearman-go/worker
|
2012-03-26 13:32:59 +08:00
|
|
|
|
2012-05-24 19:57:06 +08:00
|
|
|
Install both:
|
2012-03-26 13:32:59 +08:00
|
|
|
|
|
|
|
> $ go get bitbucket.org/mikespook/gearman-go
|
|
|
|
|
|
|
|
|
|
|
|
# SAMPLE OF 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")
|
|
|
|
w.AddFunc("ToUpper", ToUpper, 0)
|
|
|
|
w.AddFunc("ToUpperTimeOut5", ToUpper, 5)
|
|
|
|
w.Work()
|
2012-03-26 13:32:59 +08:00
|
|
|
|
|
|
|
## Client
|
|
|
|
|
2012-05-24 19:57:06 +08:00
|
|
|
c, err := client.New("127.0.0.1:4730")
|
|
|
|
// ...
|
|
|
|
defer c.Close()
|
|
|
|
echo := []byte("Hello\x00 world")
|
|
|
|
c.JobHandler = func(job *client.Job) error {
|
|
|
|
log.Printf("%s", job.Data)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
c.ErrHandler = func(e error) {
|
|
|
|
log.Println(e)
|
|
|
|
panic(e)
|
|
|
|
}
|
|
|
|
handle, err := c.Do("ToUpper", echo, client.JOB_NORMAL)
|
|
|
|
// ...
|
2012-03-26 13:32:59 +08:00
|
|
|
|
|
|
|
# Contacts
|
|
|
|
|
2012-05-24 16:56:36 +08:00
|
|
|
Xing Xing <mikespook@gmail.com>
|
2012-03-26 14:10:15 +08:00
|
|
|
|
2012-05-24 19:57:06 +08:00
|
|
|
[Blog](http://mikespook.com)
|
2012-03-26 14:10:15 +08:00
|
|
|
|
2012-05-24 19:57:06 +08:00
|
|
|
[@Twitter](http://twitter.com/mikespook)
|
2012-05-24 16:56:36 +08:00
|
|
|
|
|
|
|
# History
|
|
|
|
|
2012-06-04 23:15:42 +08:00
|
|
|
* 0.1.1 Fixed the issue of grabbing jobs.
|
2012-05-24 19:57:06 +08:00
|
|
|
* 0.1 Code refactoring; Redesign the API.
|
2012-05-24 16:56:36 +08:00
|
|
|
* 0.0.1 Initial implementation, ugly code-style, slow profermance and unstable API.
|
2012-05-24 19:21:30 +08:00
|
|
|
|
|
|
|
# TODO
|