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§

Connect to a Beanstalkd instance.

A successful TCP connect is considered the start of communication.

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 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.
  • data is the job body – a sequence of bytes of length from 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.

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

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.

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.

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.

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.

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.

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.

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

The peek command lets the client inspect a job in the system. There are four types of jobs as enumerated in PeekType. All but the first operate only on the currently used tube.

  • It takes a PeekType representing the type of peek operation to perform

  • And returns a Job on success.

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

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

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.