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 async fn add_item<C: AsyncCommands>(
&self,
db: &mut C,
item: &Item,
) -> RedisResult<bool>
pub async fn add_item<C: AsyncCommands>( &self, db: &mut C, item: &Item, ) -> RedisResult<bool>
Add an item to the work queue.
If an item with the same ID already exists, this item is not added, and false
is returned. Otherwise, if the item is added true
is returned.
If you know the item ID is unique, and not already in the queue, use the optimised
WorkQueue::add_unique_item
instead.
Sourcepub fn add_unique_item_to_pipeline(&self, pipeline: &mut Pipeline, item: &Item)
pub fn add_unique_item_to_pipeline(&self, pipeline: &mut Pipeline, item: &Item)
Add an item, which is known to have an ID not already in the queue, to the work queue. This adds the redis commands onto the pipeline passed.
Use WorkQueue::add_unique_item
if you don’t want to pass a pipeline directly.
Sourcepub async fn add_unique_item<C: AsyncCommands>(
&self,
db: &mut C,
item: &Item,
) -> RedisResult<()>
pub async fn add_unique_item<C: AsyncCommands>( &self, db: &mut C, item: &Item, ) -> RedisResult<()>
Add an item, which is known to have an ID not already in the queue, 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.