Documentation
¶
Overview ¶
Package workers provides a client for the beanstalk protocol. See http://kr.github.com/beanstalkd/ for the server.
Example ¶
mux := NewWorkMux() mux.Handle("tube1", HandlerFunc(func(job *Job) { fmt.Printf("processing job %d with content %v\n", job.ID, job.Body) job.Delete() })) mux.Handle("tube2", HandlerFunc(func(job *Job) { job.Release(0, 0) })) ConnectAndWork("tcp", "localhost:11300", mux)
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClientHasQuit = errors.New("client has quit")
ErrClientHasQuit is returned by Client when it is quitting
Functions ¶
Types ¶
type Client ¶
type Client struct { Network string Addr string Handler Handler // contains filtered or unexported fields }
Client defines parameters for running an beanstalk client.
func (*Client) ConnectAndWork ¶
ConnectAndWork connects on the c.Network and c.Addr and then calls Reserve to handle jobs on the beanstalk instance.
type Handler ¶
type Handler interface {
Work(*Job)
}
Handler defines a way for workers to handle jobs for a tube. Objects implementing the Handler interface can be registered to handle jobs for a particular tube.
type HandlerFunc ¶
type HandlerFunc func(*Job)
HandlerFunc type is an adapter to allow the use of ordinary functions as Work handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.
func (HandlerFunc) Work ¶
func (f HandlerFunc) Work(j *Job)
Work makes HandlerFunc implement the Handler interface.
type Job ¶
Job represents a job received by a worker.
func (*Job) Bury ¶
Bury buries the current job. Bury puts the job into the "buried" state. Buried jobs are put into a FIFO linked list and will not be touched by the server again until a client kicks them manually.
func (*Job) Release ¶
Release releases the current job. Release puts the reserved job back into the ready queue (and marks its state as ready) to be run by any client.
type WorkMux ¶
type WorkMux struct {
// contains filtered or unexported fields
}
WorkMux is a Beanstalkd Job multiplexer. It matches the tube of each incoming job against a list of registered tubes and calls the handler of that tube.
func (*WorkMux) Handle ¶
Handle registers the job handler for the given tube. If a handler already exists for tube, Handle panics.
func (*WorkMux) Handler ¶
Handler returns the handler to use for the given job. If there is no registered handler that applies to the job, Handler returns nil.