Version: v1.0.1 Latest Latest

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

Go to latest
Published: Jan 13, 2022 License: MIT Imports: 7 Imported by: 1



Package broker reserves jobs from beanstalkd, spawns worker processes, and manages the interaction between the two.



View Source
const (

	// TimeoutTries is the number of timeouts a job must reach before it is
	// buried. Zero means never execute.
	TimeoutTries = 1

	// ReleaseTries is the number of releases a job must reach before it is
	// buried. Zero means never execute.
	ReleaseTries = 10
View Source
const (
	// ListTubeDelay is the time between sending list-tube to beanstalkd
	// to discover and watch newly created tubes.
	ListTubeDelay = 10 * time.Second


This section is empty.


This section is empty.


type Broker

type Broker struct {

	// Address of the beanstalkd server.
	Address string

	// The shell command to execute for each job.
	Cmd string

	// Tube name this broker will service.
	Tube string
	// contains filtered or unexported fields

func New

func New(address, tube string, slot uint64, cmd string, results chan<- *JobResult) (b Broker)

New broker instance.

func (*Broker) Run

func (b *Broker) Run(ticks chan bool)

Run connects to beanstalkd and starts broking. If ticks channel is present, one job is processed per tick.

type BrokerDispatcher

type BrokerDispatcher struct {
	// contains filtered or unexported fields

BrokerDispatcher manages the running of Broker instances for tubes. It can be manually told tubes to start, or it can poll for tubes as they are created. The `perTube` option determines how many brokers are started for each tube.

func NewBrokerDispatcher

func NewBrokerDispatcher(address, cmd string, perTube uint64) *BrokerDispatcher

func (*BrokerDispatcher) RunAllTubes

func (bd *BrokerDispatcher) RunAllTubes() (err error)

RunAllTubes polls beanstalkd, running broker as new tubes are created.

func (*BrokerDispatcher) RunTube

func (bd *BrokerDispatcher) RunTube(tube string)

RunTube runs broker(s) for the specified tube. The number of brokers started is determined by the perTube argument to NewBrokerDispatcher.

func (*BrokerDispatcher) RunTubes

func (bd *BrokerDispatcher) RunTubes(tubes []string)

RunTube runs brokers for the specified tubes.

type JobResult

type JobResult struct {

	// Buried is true if the job was buried.
	Buried bool

	// Executed is true if the job command was executed (or attempted).
	Executed bool

	// ExitStatus of the command; 0 for success.
	ExitStatus int

	// JobId from beanstalkd.
	JobId uint64

	// Stdout of the command.
	Stdout []byte

	// TimedOut indicates the worker exceeded TTR for the job.
	// Note this is tracked by a timer, separately to beanstalkd.
	TimedOut bool

	// Error raised while attempting to handle the job.
	Error error

Jump to

Keyboard shortcuts

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