pub struct Beanstalk { /* private fields */ }Implementations§
Source§impl Beanstalk
impl Beanstalk
pub fn connect<A: ToSocketAddrs>(addr: A) -> Result<Self, Error>
Sourcepub fn put(
&mut self,
pri: u32,
delay: Duration,
ttr: Duration,
data: &[u8],
) -> Result<PutResponse, Error>
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\nIt inserts a job into the client’s currently used tube (see the “use” command below).
-
priis 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. -
delayis 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 withinttrseconds, 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. -
bytesis 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). -
datais the job body – a sequence of bytes of lengthbytesfrom the previous line.
Sourcepub fn use_(&mut self, tube: &str) -> Result<&str, Error>
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\ntubeis 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\ntubeis the name of the tube now being used.
Sourcepub fn reserve(
&mut self,
timeout: Option<Duration>,
) -> Result<ReserveResponse, Error>
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\nAlternatively, you can specify a timeout as follows:
reserve-with-timeout <seconds>\r\nThis 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.
Sourcepub fn reserve_by_id(&mut self, id: Id) -> Result<ReserveByIdResponse, Error>
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\nidis the job id to reserve
Sourcepub fn delete(&mut self, id: Id) -> Result<DeleteResponse, Error>
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\nidis the job id to delete.
Sourcepub fn release(
&mut self,
id: Id,
pri: u32,
delay: Duration,
) -> Result<ReleaseResponse, Error>
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-
idis the job id to release. -
priis a new priority to assign to the job. -
delayis 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.
Sourcepub fn bury(&mut self, id: Id, pri: u32) -> Result<BuryResponse, Error>
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-
idis the job id to bury. -
priis a new priority to assign to the job.
Sourcepub fn touch(&mut self, id: Id) -> Result<TouchResponse, Error>
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\nidis the ID of a job reserved by the current connection.
Sourcepub fn watch(&mut self, tube: &str) -> Result<usize, Error>
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\ntubeis 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\ncountis the integer number of tubes currently in the watch list.
Sourcepub fn ignore(&mut self, tube: &str) -> Result<IgnoreResponse, Error>
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\nSourcepub fn peek(&mut self, id: Id) -> Result<PeekResponse, Error>
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 .
Sourcepub fn peek_ready(&mut self) -> Result<PeekResponse, Error>
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.
Sourcepub fn peek_delayed(&mut self) -> Result<PeekResponse, Error>
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.
Sourcepub fn peek_buried(&mut self) -> Result<PeekResponse, Error>
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.
Sourcepub fn kick(&mut self, bound: u32) -> Result<usize, Error>
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\nboundis an integer upper bound on the number of jobs to kick. The server will kick no more thanjobs.
The response is of the form:
KICKED <count>\r\ncountis an integer indicating the number of jobs actually kicked.
Sourcepub fn kick_job(&mut self, id: Id) -> Result<KickJobResponse, Error>
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\nis the job id to kick.
Sourcepub fn stats_job(&mut self, id: Id) -> Result<StatsJobResponse, Error>
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\nis a job id.
Sourcepub fn stats_tube(&mut self, tube: &str) -> Result<StatsTubeResponse, Error>
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\nis a name at most 200 bytes. Stats will be returned for this tube.
Sourcepub fn stats(&mut self) -> Result<Stats, Error>
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\nSourcepub fn list_tubes(&mut self) -> Result<Vec<&str>, Error>
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\nSourcepub fn list_tube_used(&mut self) -> Result<&str, Error>
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\nSourcepub fn list_tube_watched(&mut self) -> Result<Vec<&str>, Error>
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\nSourcepub fn pause_tube(
&mut self,
tube: &str,
delay: Duration,
) -> Result<PauseTubeResponse, Error>
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-
tubeis the tube to pause -
delayis an integer number of seconds < 2**32 to wait before reserving any more jobs from the queue