gobeanstalk

package module
Version: v0.0.0-...-dbbb239 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2016 License: BSD-3-Clause Imports: 7 Imported by: 2

README

#gobeanstalk Build Status GoDoc Coverage Status

Go Beanstalkd client library.

INSTALL

go get github.com/iwanbk/gobeanstalk

USAGE

Producer

import (
	"github.com/iwanbk/gobeanstalk"
	"log"
	"time"
)

func main() {
	conn, err := gobeanstalk.Dial("localhost:11300")
	if err != nil {
		log.Fatal(err)
	}

	id, err := conn.Put([]byte("hello"), 0, 10*time.Second, 30*time.Second)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("Job id %d inserted\n", id)
}

Consumer

import (
	"github.com/iwanbk/gobeanstalk"
	"log"
)

func main() {
	conn, err := gobeanstalk.Dial("localhost:11300")
	if err != nil {
		log.Fatal(err)
	}
	for {
		j, err := conn.Reserve()
		if err != nil {
			log.Fatal(err)
		}
		log.Printf("id:%d, body:%s\n", j.ID, string(j.Body))
		err = conn.Delete(j.ID)
		if err != nil {
			log.Fatal(err)
		}
	}
}

Implemented Commands

  • use
  • put
  • watch
  • ignore
  • reserve
  • delete
  • touch
  • release
  • bury
  • kick
  • kick-job
  • list-tubes
  • stats
  • stats-tube
  • stats-job
  • quit

Release Notes

Latest release is v0.3 that contains API changes, see release notes here

Author

Documentation

Overview

Package gobeanstalk implement beanstalkd client library in Go.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOutOfMemory    = errors.New("out of memory")
	ErrInternalError  = errors.New("internal error")
	ErrBadFormat      = errors.New("bad format")
	ErrUnknownCommand = errors.New("unknown command")
	ErrBuried         = errors.New("buried")
	ErrExpectedCrlf   = errors.New("expected CRLF")
	ErrJobTooBig      = errors.New("job too big")
	ErrDraining       = errors.New("draining")
	ErrDeadlineSoon   = errors.New("deadline soon")
	ErrTimedOut       = errors.New("timed out")
	ErrNotFound       = errors.New("not found")
)

beanstalkd error

View Source
var (
	ErrInvalidLen = errors.New("invalid length")
	ErrUnknown    = errors.New("unknown error")
)

gobeanstalk error

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn represent a connection to beanstalkd server

func Dial

func Dial(addr string) (*Conn, error)

Dial connect to beanstalkd server

func NewConn

func NewConn(conn net.Conn, addr string) (*Conn, error)

NewConn create a new connection

func (*Conn) Bury

func (c *Conn) Bury(id uint64, pri uint32) error

Bury a job.

The bury command puts a 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 with the "kick" command.

id is the job id to bury.
pri is a new priority to assign to the job.

func (*Conn) Delete

func (c *Conn) Delete(id uint64) error

Delete delete a job given it's id

func (*Conn) Ignore

func (c *Conn) Ignore(tubename string) (int, error)

Ignore tube.

The "ignore" command is for consumers. It removes the named tube from the watch list for the current connection

func (*Conn) Kick

func (c *Conn) Kick(bound uint64) (uint64, error)

Kick jobs.

The kick command applies only to the currently used tube. It moves jobs into the ready queue. If there are any buried jobs, it will only kick buried jobs. Otherwise it will kick delayed jobs.

bound is an integer upper bound on the number of jobs to kick.

It returns an integer indicating the number of jobs actually kicked

func (*Conn) KickJob

func (c *Conn) KickJob(id uint64) error

KickJob kickcs a specific job.

If the given job id exists and is in a buried or delayed state, it will be moved to the ready queue of the the same tube where it currently belongs.

id is the job id to kick.

func (*Conn) ListTubes

func (c *Conn) ListTubes() ([]byte, error)

ListTubes returns all existing tube names the raw YAML returned by beanstalkd.

func (*Conn) Put

func (c *Conn) Put(data []byte, pri uint32, delay, ttr time.Duration) (uint64, error)

Put a job.

It inserts a job into the client's currently used tube.

data is job body.

pri is an integer < 2**32. Jobs with smaller priority values will be scheduled before jobs with larger priorities. The most urgent priority is 0; the least urgent priority is 4,294,967,295.

delay is time to wait before putting the job in the ready queue. The job will be in the "delayed" state during this time.

ttr -- time to run -- is time to allow a worker to run this job. This time is counted from the moment a worker reserves this job. If the worker does not delete, release, or bury the job within ttr time, the job will time out and the server will release the job. The minimum ttr is 1 second. If the client sends 0 second, the server will silently increase the ttr to 1 second

func (*Conn) Quit

func (c *Conn) Quit()

Quit close network connection.

func (*Conn) Release

func (c *Conn) Release(id uint64, pri uint32, delay time.Duration) error

Release a job.

The release command puts a reserved job back into the ready queue (and marks its state as "ready") to be run by any client. It is normally used when the job fails because of a transitory error.

id is the job id to release.
pri is a new priority to assign to the job.
delay is time to wait before putting the job in
	the ready queue. The job will be in the "delayed" state during this time.

func (*Conn) Reserve

func (c *Conn) Reserve(timeout ...time.Duration) (*Job, error)

Reserve Job, with an optional timeout

func (*Conn) Stats

func (c *Conn) Stats() ([]byte, error)

Stats fetch system stats

The "stats" command is for both producers/consumers and passes through the raw YAML returned by beanstalkd.

func (*Conn) StatsJob

func (c *Conn) StatsJob(id uint64) ([]byte, error)

StatsJob fetch job stats

The "stats-job" command is for both producers/consumers and passes through the raw YAML returned by beanstalkd for the given job ID.

func (*Conn) StatsTube

func (c *Conn) StatsTube(tubename string) ([]byte, error)

StatsTube fetch tubs stats

The "stats-tube" command is for both producers/consumers and passes through the raw YAML returned by beanstalkd for the given tube name.

func (*Conn) Touch

func (c *Conn) Touch(id uint64) error

Touch a job

The "touch" command allows a worker to request more time to work on a job. This is useful for jobs that potentially take a long time, but you still want the benefits of a TTR pulling a job away from an unresponsive worker. A worker may periodically tell the server that it's still alive and processing a job (e.g. it may do this on DEADLINE_SOON)

func (*Conn) Use

func (c *Conn) Use(tubename string) error

Use tube

The "use" command is for producers. Subsequent put commands will put jobs into the tube specified by this command. If no use command has been issued, jobs will be put into the tube named "default".

func (*Conn) Watch

func (c *Conn) Watch(tubename string) (int, error)

Watch a tube

type Job

type Job struct {
	ID   uint64
	Body []byte
}

Job represent beanstalkd job

func NewJob

func NewJob(id uint64, body []byte) *Job

NewJob create a new job

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL