Go to file
Paul Cameron a8f0a04c3d Fix two race conditions in client.Do
* Common race condition is fixed by identifying that Client.respHandler
  can be completely removed since all respHandler operations (get, put
  and invocation) can be moved into the Client.processLoop goroutine,
  meaning that zero locking is required. This race condition resulted
  in a deadlock that was resolved by the response timeout at the
  end of client.Do, returning ErrLostConn

* Rare race condition is fixed by changing responseHandlerMap.get
  to .getAndRemove. This race condition resulted in the innerHandler
  for a new dtJobCreated assigned in client.Do overriding a stale older
  dtJobCreated request, and the newer innerHandler being removed by an
  older dtJobCreated in client.processLoop > client.handleInner. When
  the newer dtJobCreated response was received, the handler for it had
  already been deleted. This was resolved by the response timeout at the
  end of client.Do, returning ErrLostConn
2021-05-02 11:31:19 +10:00
client Fix two race conditions in client.Do 2021-05-02 11:31:19 +10:00
example Fix two race conditions in client.Do 2021-05-02 11:31:19 +10:00
worker add synchronization to prevent race condition on worker shutdown (#89) 2019-05-28 18:41:20 +08:00
.gitignore Initial commit 2012-12-20 18:51:15 -08:00
.travis.yml upgrade travis to Go 1.4 2015-01-10 00:09:38 +08:00
gearman.go Remove unused imports 2017-09-27 16:57:03 +02:00
LICENSE Added the client 2011-05-19 20:10:53 +08:00
README.md 80 chars/line 2015-01-20 10:28:36 +08:00

Gearman-Go

This module is a Gearman API for the Go Programming Language. 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"

Build Status GoDoc

Install

Install the client package:

$ go get github.com/mikespook/gearman-go/client

Install the worker package:

$ go get github.com/mikespook/gearman-go/worker

Both of them:

$ go get github.com/mikespook/gearman-go

Usage

Worker

// Limit number of concurrent jobs execution. 
// Use worker.Unlimited (0) if you want no limitation.
w := worker.New(worker.OneByOne)
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
w.AddFunc("ToUpperTimeOut5", ToUpper, 5)

if err := w.Ready(); err != nil {
	log.Fatal(err)
	return
}
go w.Work()

Client

// ...
c, err := client.New("tcp4", "127.0.0.1:4730")
// ... error handling
defer c.Close()
c.ErrorHandler = func(e error) {
	log.Println(e)
}
echo := []byte("Hello\x00 world")
echomsg, err := c.Echo(echo)
// ... error handling
log.Println(string(echomsg))
jobHandler := func(resp *client.Response) {
	log.Printf("%s", resp.Data)
}
handle, err := c.Do("ToUpper", echo, client.JobNormal, jobHandler)
// ...	

Branches

Version 0.x means: It is far far away from stable.

Use at your own risk!

  • master current usable version
  • 0.2-dev Refactoring a lot of things
  • 0.1-testing Old API and some known issues, eg. issue-14

Contributors

Great thanks to all of you for your support and interest!

(Alphabetic order)

Maintainer

Open Source - MIT Software License

See LICENSE.