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 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]

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.

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);

Get the number of remaining tasks for this queue.

Delete all remaining entries in the task queue.

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.

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.

Get the oldest job in the queue.

Fetch a specific job by id.

Delete result of a specific job from the backend

Delete results of all jobs in the queue from the backend

Auto Trait Implementations

impl Send for Brokkr

impl !Sync for Brokkr