Crate robin [] [src]

Robin

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:

#[macro_use]
extern crate robin;
#[macro_use]
extern crate serde_derive;
use robin::prelude::*;

jobs! {
    MyJob,
}

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

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

let config = Config::default();

let con = robin_establish_connection!(config)?;

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

robin_boot_worker!(config);

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

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::*;

Modules

config

Contains the config type used to configure Robin.

connection

Contains the connection type and functions for establishing connections.

error

Contains the error and result types used throughout Robin.

job

Contains traits for enqueueing and performing jobs.

macros

Contains the macros exported by 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.

worker

Contains functions for booting and running workers which perform jobs.

Macros

jobs
robin_boot_worker
robin_establish_connection