Beanstalk

Struct Beanstalk 

Source
pub struct Beanstalk { /* private fields */ }

Implementations§

Source§

impl Beanstalk

Source

pub fn connect<A: ToSocketAddrs>(addr: A) -> Result<Self, Error>

Source

pub fn put( &mut self, pri: u32, delay: Duration, ttr: Duration, data: &[u8], ) -> Result<PutResponse, Error>

The “put” command is for any process that wants to insert a job into the queue. It comprises a command line followed by the job body:

put <pri> <delay> <ttr> <bytes>\r\n
<data>\r\n

It inserts a job into the client’s currently used tube (see the “use” command below).

  • 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 an integer number of seconds to wait before putting the job in the ready queue. The job will be in the “delayed” state during this time. Maximum delay is 2**32-1.

  • ttr – time to run – is an integer number of seconds 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 seconds, the job will time out and the server will release the job. The minimum ttr is 1. If the client sends 0, the server will silently increase the ttr to 1. Maximum ttr is 2**32-1.

  • bytes is an integer indicating the size of the job body, not including the trailing “\r\n”. This value must be less than max-job-size (default: 2**16).

  • data is the job body – a sequence of bytes of length bytes from the previous line.

Source

pub fn use_(&mut self, tube: &str) -> Result<&str, Error>

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”.

use <tube>\r\n
  • tube is a name at most 200 bytes. It specifies the tube to use. If the tube does not exist, it will be created.

The only reply is:

 USING <tube>\r\n
  • tube is the name of the tube now being used.
Source

pub fn reserve( &mut self, timeout: Option<Duration>, ) -> Result<ReserveResponse, Error>

A process that wants to consume jobs from the queue uses “reserve”, “delete”, “release”, and “bury”. The first worker command, “reserve”, looks like this:

reserve\r\n

Alternatively, you can specify a timeout as follows:

reserve-with-timeout <seconds>\r\n

This will return a newly-reserved job. If no job is available to be reserved, beanstalkd will wait to send a response until one becomes available. Once a job is reserved for the client, the client has limited time to run (TTR) the job before the job times out. When the job times out, the server will put the job back into the ready queue. Both the TTR and the actual time left can be found in response to the stats-job command.

If more than one job is ready, beanstalkd will choose the one with the smallest priority value. Within each priority, it will choose the one that was received first.

A timeout value of 0 will cause the server to immediately return either a response or TIMED_OUT. A positive value of timeout will limit the amount of time the client will block on the reserve request until a job becomes available.

Source

pub fn reserve_by_id(&mut self, id: Id) -> Result<ReserveByIdResponse, Error>

A job can be reserved by its id. Once a job is reserved for the client, the client has limited time to run (TTR) the job before the job times out. When the job times out, the server will put the job back into the ready queue. The command looks like this:

reserve-job <id>\r\n
  • id is the job id to reserve
Source

pub fn delete(&mut self, id: Id) -> Result<DeleteResponse, Error>

The delete command removes a job from the server entirely. It is normally used by the client when the job has successfully run to completion. A client can delete jobs that it has reserved, ready jobs, delayed jobs, and jobs that are buried. The delete command looks like this:

delete <id>\r\n
  • id is the job id to delete.
Source

pub fn release( &mut self, id: Id, pri: u32, delay: Duration, ) -> Result<ReleaseResponse, Error>

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. It looks like this:

release <id> <pri> <delay>\r\n
  • id is the job id to release.

  • pri is a new priority to assign to the job.

  • delay is an integer number of seconds to wait before putting the job in the ready queue. The job will be in the “delayed” state during this time.

Source

pub fn bury(&mut self, id: Id, pri: u32) -> Result<BuryResponse, Error>

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.

The bury command looks like this:

bury <id> <pri>\r\n
  • id is the job id to bury.

  • pri is a new priority to assign to the job.

Source

pub fn touch(&mut self, id: Id) -> Result<TouchResponse, Error>

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). The command postpones the auto release of a reserved job until TTR seconds from when the command is issued.

The touch command looks like this:

touch <id>\r\n
  • id is the ID of a job reserved by the current connection.
Source

pub fn watch(&mut self, tube: &str) -> Result<usize, Error>

The “watch” command adds the named tube to the watch list for the current connection. A reserve command will take a job from any of the tubes in the watch list. For each new connection, the watch list initially consists of one tube, named “default”.

watch <tube>\r\n
  • tube is a name at most 200 bytes. It specifies a tube to add to the watch list. If the tube doesn’t exist, it will be created.

The response is:

WATCHING <count>\r\n
  • count is the integer number of tubes currently in the watch list.
Source

pub fn ignore(&mut self, tube: &str) -> Result<IgnoreResponse, Error>

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

ignore <tube>\r\n
Source

pub fn peek(&mut self, id: Id) -> Result<PeekResponse, Error>

The peek command let the client inspect a job in the system.

  • “peek \r\n” - return job .
Source

pub fn peek_ready(&mut self) -> Result<PeekResponse, Error>

The peek command let the client inspect a job in the system. Operate only on the currently used tube.

  • “peek-ready\r\n” - return the next ready job.
Source

pub fn peek_delayed(&mut self) -> Result<PeekResponse, Error>

The peek command let the client inspect a job in the system. Operate only on the currently used tube.

  • “peek-delayed\r\n” - return the delayed job with the shortest delay left.
Source

pub fn peek_buried(&mut self) -> Result<PeekResponse, Error>

The peek command let the client inspect a job in the system. Operate only on the currently used tube.

  • “peek-buried\r\n” - return the next job in the list of buried jobs.
Source

pub fn kick(&mut self, bound: u32) -> Result<usize, Error>

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. It looks like:

kick <bound>\r\n
  • bound is an integer upper bound on the number of jobs to kick. The server will kick no more than jobs.

The response is of the form:

KICKED <count>\r\n
  • count is an integer indicating the number of jobs actually kicked.
Source

pub fn kick_job(&mut self, id: Id) -> Result<KickJobResponse, Error>

The kick-job command is a variant of kick that operates with a single job identified by its job id. 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. The syntax is:

kick-job <id>\r\n
  • is the job id to kick.
Source

pub fn stats_job(&mut self, id: Id) -> Result<StatsJobResponse, Error>

The stats-job command gives statistical information about the specified job if it exists. Its form is:

stats-job <id>\r\n
  • is a job id.
Source

pub fn stats_tube(&mut self, tube: &str) -> Result<StatsTubeResponse, Error>

The stats-tube command gives statistical information about the specified tube if it exists. Its form is:

stats-tube <tube>\r\n
  • is a name at most 200 bytes. Stats will be returned for this tube.
Source

pub fn stats(&mut self) -> Result<Stats, Error>

The stats command gives statistical information about the system as a whole. Its form is:

stats\r\n
Source

pub fn list_tubes(&mut self) -> Result<Vec<&str>, Error>

The list-tubes command returns a list of all existing tubes. Its form is:

  list-tubes\r\n
Source

pub fn list_tube_used(&mut self) -> Result<&str, Error>

The list-tube-used command returns the tube currently being used by the client. Its form is:

list-tube-used\r\n
Source

pub fn list_tube_watched(&mut self) -> Result<Vec<&str>, Error>

The list-tubes-watched command returns a list tubes currently being watched by the client. Its form is:

list-tubes-watched\r\n
Source

pub fn pause_tube( &mut self, tube: &str, delay: Duration, ) -> Result<PauseTubeResponse, Error>

The pause-tube command can delay any new job being reserved for a given time. Its form is:

 pause-tube <tube-name> <delay>\r\n
  • tube is the tube to pause

  • delay is an integer number of seconds < 2**32 to wait before reserving any more jobs from the queue

Source

pub fn quit(self) -> Result<(), Error>

The quit command simply closes the connection. Its form is:

 quit\r\n

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.