Struct tokio_beanstalkd::Beanstalkd
source · pub struct Beanstalkd { /* private fields */ }
Expand description
Connection to the Beanstalkd server.
All interactions with Beanstalkd happen by calling methods on a Beanstalkd
instance.
Even though there is a quit
command, Beanstalkd consideres a closed connection as the
end of communication, so just dropping this struct will close the connection.
Implementations§
source§impl Beanstalkd
impl Beanstalkd
sourcepub fn connect(addr: &SocketAddr) -> impl Future<Item = Self, Error = Error>
pub fn connect(addr: &SocketAddr) -> impl Future<Item = Self, Error = Error>
Connect to a Beanstalkd instance.
A successful TCP connect is considered the start of communication.
sourcepub fn put<D>(
self,
priority: u32,
delay: u32,
ttr: u32,
data: D
) -> impl Future<Item = (Self, Result<Id, Put>), Error = Error>where
D: Into<Cow<'static, [u8]>>,
pub fn put<D>(
self,
priority: u32,
delay: u32,
ttr: u32,
data: D
) -> impl Future<Item = (Self, Result<Id, Put>), Error = Error>where
D: Into<Cow<'static, [u8]>>,
The “put” command is for any process that wants to insert a job into the queue.
It inserts a job into the client’s currently used tube (see the use
command
below).
priority
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.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 withinttr
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.data
is the job body – a sequence of bytes of lengthfrom the previous line.
After sending the command line and body, the client waits for a reply, which is the integer id of the new job.
sourcepub fn reserve(
self
) -> impl Future<Item = (Self, Result<Job, Consumer>), Error = Error>
pub fn reserve(
self
) -> impl Future<Item = (Self, Result<Job, Consumer>), Error = Error>
Reserve a job to process.
FIXME: need to handle different responses returned at different TTR vs reserve-with-timeout times
A process that wants to consume jobs from the queue uses reserve
,
[delete](tokio_beanstalkd::delete)
,
[release](tokio_beanstalkd::release)
, and
[bury](tokio_beanstalkd::bury)
.
sourcepub fn using(
self,
tube: &'static str
) -> impl Future<Item = (Self, Result<Tube, BeanstalkError>), Error = Error>
pub fn using(
self,
tube: &'static str
) -> impl Future<Item = (Self, Result<Tube, BeanstalkError>), Error = 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”.
tube
is a name at most 200 bytes. It specifies the tube to use. If the tube does not exist, it will be created.
sourcepub fn delete(
self,
id: u32
) -> impl Future<Item = (Self, Result<(), Consumer>), Error = Error>
pub fn delete(
self,
id: u32
) -> impl Future<Item = (Self, Result<(), Consumer>), Error = 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.
id
is the job id to delete.
sourcepub fn release(
self,
id: u32,
priority: u32,
delay: u32
) -> impl Future<Item = (Self, Result<(), Consumer>), Error = Error>
pub fn release(
self,
id: u32,
priority: u32,
delay: u32
) -> impl Future<Item = (Self, Result<(), Consumer>), Error = 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.
-
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.
sourcepub fn touch(
self,
id: u32
) -> impl Future<Item = (Self, Result<(), Consumer>), Error = Error>
pub fn touch(
self,
id: u32
) -> impl Future<Item = (Self, Result<(), Consumer>), Error = 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.
id
is the ID of a job reserved by the current connection.
sourcepub fn bury(
self,
id: u32,
priority: u32
) -> impl Future<Item = (Self, Result<(), Consumer>), Error = Error>
pub fn bury(
self,
id: u32,
priority: u32
) -> impl Future<Item = (Self, Result<(), Consumer>), Error = 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.
-
id
is the job id to release. -
prioritiy
is a new priority to assign to the job.
sourcepub fn watch(
self,
tube: &'static str
) -> impl Future<Item = (Self, Result<u32, BeanstalkError>), Error = Error>
pub fn watch(
self,
tube: &'static str
) -> impl Future<Item = (Self, Result<u32, BeanstalkError>), Error = 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”.
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 value returned is the count of the tubes being watched by the current connection.
sourcepub fn ignore(
self,
tube: &'static str
) -> impl Future<Item = (Self, Result<u32, Consumer>), Error = Error>
pub fn ignore(
self,
tube: &'static str
) -> impl Future<Item = (Self, Result<u32, Consumer>), Error = Error>
The “ignore” command is for consumers. It removes the named tube from the watch list for the current connection.
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.
A successful response is:
- The count of the number of tubes currently watching
sourcepub fn peek(
self,
peek_type: PeekType
) -> impl Future<Item = (Self, Result<Job, Consumer>), Error = Error>
pub fn peek(
self,
peek_type: PeekType
) -> impl Future<Item = (Self, Result<Job, Consumer>), Error = Error>
sourcepub fn kick(
self,
bound: u32
) -> impl Future<Item = (Self, Result<u32, Consumer>), Error = Error>
pub fn kick(
self,
bound: u32
) -> impl Future<Item = (Self, Result<u32, Consumer>), Error = 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 takes a
bound
which is the number of jobs it will kick - The response is a u32 representing the number of jobs kicked by the server
sourcepub fn kick_job(
self,
id: Id
) -> impl Future<Item = (Self, Result<(), Consumer>), Error = Error>
pub fn kick_job(
self,
id: Id
) -> impl Future<Item = (Self, Result<(), Consumer>), Error = 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.
- It takes an
id
of the job to be kicked - And returns
()
on success