3 releases (breaking)

Uses old Rust 2015

0.3.0 Apr 8, 2018
0.2.0 Apr 7, 2018
0.1.0 Apr 4, 2018

#13 in #background

MIT license

669 lines

This is the readme for the main Robin crate. You can find help at our GitHub repo.



Robin lets you run jobs in the background. This could for example be payment processing or sending emails.

If you've used ActiveJob from Ruby on Rails you'll feel right at home.

Getting started

The standard way to use Robin is through the jobs! macro. It takes a comma separated list of job names, and generates all the boilerplate for you. Just you have to define a static method named perform on each of your jobs.

Here is a full example:

extern crate robin;
extern crate serde_derive;
# use std::error::Error;
# fn main() { try_main().expect("try_main failed") }
# fn try_main() -> Result<(), Box<Error>> {
use robin::prelude::*;

jobs! {

impl MyJob {
    fn perform(args: JobArgs, _con: &WorkerConnection) -> JobResult {
        println!("Job performed with {:?}", args);

#[derive(Serialize, Deserialize, Debug)]
pub struct JobArgs;

let config = Config::default();
# let mut config = Config::default();
# config.timeout = 1;
# config.redis_namespace = "doc_tests_for_crate".to_string();
# config.repeat_on_timeout = false;
# config.retry_count_limit = 1;
# config.worker_count = 1;

let con = robin_establish_connection!(config)?;
# con.delete_all();

assert_eq!(con.main_queue_size()?, 0);
assert_eq!(con.retry_queue_size()?, 0);

for i in 0..5 {
    MyJob::perform_later(&JobArgs, &con)?;

assert_eq!(con.main_queue_size()?, 5);
assert_eq!(con.retry_queue_size()?, 0);


assert_eq!(con.main_queue_size()?, 0);
assert_eq!(con.retry_queue_size()?, 0);
# Ok(())
# }

Normally the code that enqueues jobs and the code the boots the worker would be in separate binaries.

For more details see the robin::macros module documentation.

The prelude

Robin provides a prelude module which exports all the commonly used types and traits. Code using Robin is expected to have:

use robin::prelude::*;

Reexports the most commonly used types and traits from the other modules. As long as you're doing standard things this is the only use you'll need.


~134K SLoC