Documentation ¶
Overview ¶
Package beanstalk provides a client for the beanstalk protocol. See http://kr.github.com/beanstalkd/ for the server.
This package is synchronized internally and safe to use from multiple goroutines without other coordination.
Example (Put) ¶
package main import ( "fmt" "github.com/kr/beanstalk" "time" ) var conn, _ = beanstalk.Dial("tcp", "127.0.0.1:11300") func main() { id, err := conn.Put([]byte("myjob"), 1, 0, time.Minute) if err != nil { panic(err) } fmt.Println("job", id) }
Output:
Example (PutOtherTube) ¶
package main import ( "fmt" "github.com/kr/beanstalk" "time" ) var conn, _ = beanstalk.Dial("tcp", "127.0.0.1:11300") func main() { tube := &beanstalk.Tube{conn, "mytube"} id, err := tube.Put([]byte("myjob"), 1, 0, time.Minute) if err != nil { panic(err) } fmt.Println("job", id) }
Output:
Example (Reserve) ¶
package main import ( "fmt" "github.com/kr/beanstalk" "time" ) var conn, _ = beanstalk.Dial("tcp", "127.0.0.1:11300") func main() { id, body, err := conn.Reserve(5 * time.Second) if err != nil { panic(err) } fmt.Println("job", id) fmt.Println(string(body)) }
Output:
Example (ReserveOtherTubeSet) ¶
package main import ( "fmt" "github.com/kr/beanstalk" "time" ) var conn, _ = beanstalk.Dial("tcp", "127.0.0.1:11300") func main() { tubeSet := beanstalk.NewTubeSet(conn, "mytube1", "mytube2") id, body, err := tubeSet.Reserve(10 * time.Hour) if err != nil { panic(err) } fmt.Println("job", id) fmt.Println(string(body)) }
Output:
Index ¶
- Constants
- Variables
- type Conn
- func (c *Conn) Bury(id uint64, pri uint32) error
- func (c *Conn) Close() error
- func (c *Conn) Delete(id uint64) error
- func (c *Conn) ListTubes() ([]string, error)
- func (c *Conn) Peek(id uint64) (body []byte, err error)
- func (c *Conn) Release(id uint64, pri uint32, delay time.Duration) error
- func (c *Conn) Stats() (map[string]string, error)
- func (c *Conn) StatsJob(id uint64) (map[string]string, error)
- func (c *Conn) Touch(id uint64) error
- func (c *Conn) UseTube(name string) error
- func (c *Conn) UseTubes(name ...string) error
- type ConnError
- type IConn
- type NameError
- type Pool
- type Tube
- func (t *Tube) Kick(bound int) (n int, err error)
- func (t *Tube) Pause(d time.Duration) error
- func (t *Tube) PeekBuried() (id uint64, body []byte, err error)
- func (t *Tube) PeekDelayed() (id uint64, body []byte, err error)
- func (t *Tube) PeekReady() (id uint64, body []byte, err error)
- func (t *Tube) Put(body []byte, pri uint32, delay, ttr time.Duration) (id uint64, err error)
- func (t *Tube) Stats() (map[string]string, error)
- type TubeSet
Examples ¶
Constants ¶
const NameChars = `\-+/;.$_()0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`
Characters allowed in a name in the beanstalkd protocol.
Variables ¶
var ( ErrBadFormat = errors.New("bad command format") ErrBuried = errors.New("buried") ErrDeadline = errors.New("deadline soon") ErrDraining = errors.New("draining") ErrInternal = errors.New("internal error") ErrJobTooBig = errors.New("job too big") ErrNoCRLF = errors.New("expected CR LF") ErrNotFound = errors.New("not found") ErrNotIgnored = errors.New("not ignored") ErrOOM = errors.New("server is out of memory") ErrTimeout = errors.New("timeout") ErrUnknown = errors.New("unknown command") )
Error messages returned by the server.
var ( ErrEmpty = errors.New("name is empty") ErrBadChar = errors.New("name has bad char") // contains a character not in NameChars ErrTooLong = errors.New("name is too long") )
Name format errors. The Err field of NameError contains one of these.
var ErrPoolExhausted = errors.New("beanstalk: connection pool exhausted")
Functions ¶
This section is empty.
Types ¶
type Conn ¶
A Conn represents a connection to a beanstalkd server. It consists of a default Tube and TubeSet as well as the underlying network connection. The embedded types carry methods with them; see the documentation of those types for details.
func Dial ¶
Dial connects to the given address on the given network using net.Dial and then returns a new Conn for the connection.
func NewConn ¶
func NewConn(conn io.ReadWriteCloser) *Conn
NewConn returns a new Conn using conn for I/O.
func (*Conn) Bury ¶
Bury places the given job in a holding area in the job's tube and sets its priority to pri. The job will not be scheduled again until it has been kicked; see also the documentation of Kick.
func (*Conn) ListTubes ¶
ListTubes returns the names of the tubes that currently exist on the server.
func (*Conn) Release ¶
Release tells the server to perform the following actions: set the priority of the given job to pri, remove it from the list of jobs reserved by c, wait delay seconds, then place the job in the ready queue, which makes it available for reservation by any client.
type ConnError ¶
ConnError records an error message from the server and the operation and connection that caused it.
type IConn ¶
type IConn interface { Close() error Delete(uint64) error Release(uint64, uint32, time.Duration) error Bury(uint64, uint32) error Touch(uint64) error Peek(uint64) ([]byte, error) Stats() (map[string]string, error) StatsJob(uint64) (map[string]string, error) ListTubes() ([]string, error) // Implemented in tube Put(body []byte, pri uint32, delay, ttr time.Duration) (id uint64, err error) PeekReady() (id uint64, body []byte, err error) PeekDelayed() (id uint64, body []byte, err error) PeekBuried() (id uint64, body []byte, err error) Kick(bound int) (n int, err error) Pause(d time.Duration) error // Implemented in tubeset Reserve(timeout time.Duration) (id uint64, body []byte, err error) UseTube(name string) error UseTubes(name ...string) error }
type NameError ¶
NameError indicates that a name was malformed and the specific error describing how.
type Pool ¶
type Pool struct { // Dial is an application supplied function for creating and configuring a // connection. // // The connection returned from Dial must not be in a special state // (subscribed to pubsub channel, transaction started, ...). Dial func() (IConn, error) // TestOnBorrow is an optional application supplied function for checking // the health of an idle connection before the connection is used again by // the application. Argument t is the time that the connection was returned // to the pool. If the function returns an error, then the connection is // closed. TestOnBorrow func(c IConn, t time.Time) error // Maximum number of idle connections in the pool. MaxIdle int // Maximum number of connections allocated by the pool at a given time. // When zero, there is no limit on the number of connections in the pool. MaxActive int // Close connections after remaining idle for this duration. If the value // is zero, then idle connections are not closed. Applications should set // the timeout to a value less than the server's timeout. IdleTimeout time.Duration // If Wait is true and the pool is at the MaxActive limit, then Get() waits // for a connection to be returned to the pool before returning. Wait bool // contains filtered or unexported fields }
func (*Pool) ActiveCount ¶
ActiveCount returns the number of active connections in the pool.
func (*Pool) Get ¶
Get gets a connection. The application must close the returned connection. This method always returns a valid connection so that applications can defer error handling to the first use of the connection. If there is an error getting an underlying connection, then the connection Err, Do, Send, Flush and Receive methods return that error.
type Tube ¶
Tube represents tube Name on the server connected to by Conn. It has methods for commands that operate on a single tube.
func (*Tube) Kick ¶
Kick takes up to bound jobs from the holding area and moves them into the ready queue, then returns the number of jobs moved. Jobs will be taken in the order in which they were last buried.
func (*Tube) PeekBuried ¶
PeekBuried gets a copy of the job in the holding area that would be kicked next by Kick.
func (*Tube) PeekDelayed ¶
PeekDelayed gets a copy of the delayed job that is next to be put in t's ready queue.
type TubeSet ¶
TubeSet represents a set of tubes on the server connected to by Conn. Name names the tubes represented.
func NewTubeSet ¶
NewTubeSet returns a new TubeSet representing the given names.