Struct redis_work_queue::WorkQueue 
source · pub struct WorkQueue { /* private fields */ }Expand description
A work queue backed by a redis database
Implementations§
source§impl WorkQueue
 
impl WorkQueue
pub fn new(name: KeyPrefix) -> WorkQueue
sourcepub fn add_item_to_pipeline(&self, pipeline: &mut Pipeline, item: &Item)
 
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.
sourcepub async fn add_item<C: AsyncCommands>(
    &self,
    db: &mut C,
    item: &Item
) -> RedisResult<()>
 
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.
sourcepub fn queue_len<'a, C: AsyncCommands>(
    &'a self,
    db: &'a mut C
) -> impl Future<Output = RedisResult<usize>> + 'a
 
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).
sourcepub fn processing<'a, C: AsyncCommands>(
    &'a self,
    db: &'a mut C
) -> impl Future<Output = RedisResult<usize>> + 'a
 
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.
sourcepub async fn lease<C: AsyncCommands>(
    &self,
    db: &mut C,
    timeout: Option<Duration>,
    lease_duration: Duration
) -> RedisResult<Option<Item>>
 
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.
sourcepub async fn complete<C: AsyncCommands>(
    &self,
    db: &mut C,
    item: &Item
) -> RedisResult<bool>
 
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.