Struct brokkr::Brokkr [−][src]
pub struct Brokkr { pub name: String, // some fields omitted }
Interface with the Redis backend.
Usage
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] struct Task { name: String } #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] struct TaskResult; let brkkr = Brokkr::new("example_queue".to_owned()); let job_id = brkkr.enqueue::<Task, TaskResult>(Task { name: "foo".to_owned() }).unwrap(); match brkkr.dequeue::<Task, TaskResult>().unwrap() { Some(j) => { assert_eq!(j.task, Task { name: "foo".to_owned() }); assert_eq!(j.result, None); assert_eq!(j.id, job_id); // You can now do something with it. }, None => panic!("Someone stole my job"), } // No more jobs to process assert!(brkkr.dequeue::<Task, TaskResult>().unwrap().is_none());
Fields
name: String
Name of the queue.
All the items stored in redis that are related to this queue will be
prefixed with brokkr:{name}:
to make it easy to inspect the redis server
directly.
Methods
impl Brokkr
[src]
impl Brokkr
pub fn new(name: String) -> Self
[src]
pub fn new(name: String) -> Self
Create a new Brokkr
.
The Redis url is taken from the BROKKR_URL
env variable falling
back to redis://127.0.0.1/
.
You can add a password by prepending :password
to the host.
Arguments
name
- Name of the queue.
pub fn with_connection(name: String, conn: Connection) -> Self
[src]
pub fn with_connection(name: String, conn: Connection) -> Self
Create a new Brokkr
with an explicit Redis connection. Use this if the
default behaviour isn't suitable for your use case.
Arguments
name
- Name of the queue.conn
- Already constructed Redis connection.
Usage
let client = redis::Client::open("redis://127.0.0.1/").unwrap(); let con = client.get_connection().unwrap(); let brkkr = Brokkr::with_connection("default".to_owned(), con);
pub fn queue_size(&self) -> u64
[src]
pub fn queue_size(&self) -> u64
Get the number of remaining tasks for this queue.
pub fn clear_queue(&self) -> Result<()>
[src]
pub fn clear_queue(&self) -> Result<()>
Delete all remaining entries in the task queue.
pub fn clear_all(&self) -> Result<()>
[src]
pub fn clear_all(&self) -> Result<()>
Delete all keys related to this queue, including workers semaphores, task results and failures.
Only use this if you are sure that all workers have been correctly stopped and results gathered as this might leave other processes in an inconcistent state.
pub fn enqueue<T: Encodable, R: Encodable>(&self, task: T) -> Result<Uuid>
[src]
pub fn enqueue<T: Encodable, R: Encodable>(&self, task: T) -> Result<Uuid>
Push a task to the queue.
Teh result is the resulting job's uuid which can be used for later
processing such a retrieving its result or failure information with
fetch_job
.
pub fn dequeue<T: Encodable, R: Encodable>(&self) -> Result<Option<Job<T, R>>>
[src]
pub fn dequeue<T: Encodable, R: Encodable>(&self) -> Result<Option<Job<T, R>>>
Get the oldest job in the queue.
pub fn fetch_job<T: Encodable, R: Encodable>(
&self,
job_id: &Uuid
) -> Result<Option<Job<T, R>>>
[src]
pub fn fetch_job<T: Encodable, R: Encodable>(
&self,
job_id: &Uuid
) -> Result<Option<Job<T, R>>>
Fetch a specific job by id.
pub fn delete_job_result(&self, job_id: &Uuid) -> Result<()>
[src]
pub fn delete_job_result(&self, job_id: &Uuid) -> Result<()>
Delete result of a specific job from the backend
pub fn delete_all_job_results(&self) -> Result<()>
[src]
pub fn delete_all_job_results(&self) -> Result<()>
Delete results of all jobs in the queue from the backend