pub struct WorkQueue { /* private fields */ }
Expand description

A work queue backed by a redis database

Implementations§

source§

impl WorkQueue

source

pub fn new(name: KeyPrefix) -> WorkQueue

source

pub fn add_item_to_pipeline(&self, pipeline: &mut Pipeline, item: &Item)

Add an item to the work queue. This adds the redis commands onto the pipeline passed.

Use WorkQueue::add_item if you don’t want to pass a pipeline directly.

source

pub async fn add_item<C: AsyncCommands>( &self, db: &mut C, item: &Item ) -> RedisResult<()>

Add an item to the work queue.

This creates a pipeline and executes it on the database.

source

pub fn queue_len<'a, C: AsyncCommands>( &'a self, db: &'a mut C ) -> impl Future<Output = RedisResult<usize>> + 'a

Return the length of the work queue (not including items being processed, see WorkQueue::processing).

source

pub fn processing<'a, C: AsyncCommands>( &'a self, db: &'a mut C ) -> impl Future<Output = RedisResult<usize>> + 'a

Return the number of items being processed.

source

pub async fn lease<C: AsyncCommands>( &self, db: &mut C, timeout: Option<Duration>, lease_duration: Duration ) -> RedisResult<Option<Item>>

Request a work lease the work queue. This should be called by a worker to get work to complete. When completed, the complete method should be called.

The function will return either when a job is leased or after timeout if timeout isn’t None.

If the job is not completed (by calling WorkQueue::complete) before the end of lease_duration, another worker may pick up the same job. It is not a problem if a job is marked as done more than once.

If you’ve not already done it, it’s worth reading the documentation on leasing items.

source

pub async fn complete<C: AsyncCommands>( &self, db: &mut C, item: &Item ) -> RedisResult<bool>

Marks a job as completed and remove it from the work queue. After complete has been called (and returns true), no workers will receive this job again.

complete returns a boolean indicating if the job has been removed and this worker was the first worker to call complete. So, while lease might give the same job to multiple workers, complete will return true for only one worker.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more