pub struct Queue<T> { /* private fields */ }
Expand description
A durable queue backed by the filesystem.
This queue stores items of type T as files in a spool directory. Files are serialized with serde_json so T must derive serde’s Serialize and Deserialize traits.
The queue’s directory should only contain items of the same type. Any files in the spool that fail to deserialize will be discarded.
Implementations§
Source§impl<T: Serialize + Deserialize> Queue<T>
impl<T: Serialize + Deserialize> Queue<T>
Sourcepub fn new(path: &str) -> Result<Queue<T>, Error>
pub fn new(path: &str) -> Result<Queue<T>, Error>
Create a new Queue<T>
using the given directory path for storage.
Sourcepub fn pop(&self) -> Result<Option<T>, Error>
pub fn pop(&self) -> Result<Option<T>, Error>
Pop an item off the queue.
This method returns the first matching directory entry. Queue ordering cannot be guaranteed to be consistent across all operating systems and filesystems, as the serialized file will be chosen based on the filesystem’s directory entry ordering.
Popped items are not removed from the filesystem immediately; instead, they are marked for deletion. Use flush() to cause the items to be permanently removed from the underlying filesystem.
Sourcepub fn pop_filter<F>(&self, filter: F) -> Result<Option<T>, Error>
pub fn pop_filter<F>(&self, filter: F) -> Result<Option<T>, Error>
Pop an item off the queue matching the filter function.
This method works the same as pop(), except the item must match the given function or it is not popped off the queue.
pub fn drain(&self) -> Result<Vec<T>, Error>
Sourcepub fn flush(&self) -> Result<(), Error>
pub fn flush(&self) -> Result<(), Error>
Flush removes all pending item files marked for deletion.
Sourcepub fn recover(&self) -> Result<(), Error>
pub fn recover(&self) -> Result<(), Error>
Recover unmarks all pending item files that were previously marked for deletion.
Use recover to ensure that popped items are processed at least once, when it is uncertain whether they were processed due to a crash.
This method is only recommended if items are being processed idempotently.