Crate robin [−] [src]
Robin
Robin lets you run jobs in the background. This could be payment processing or sending emails. Inspired by ActiveJob from Ruby on Rails.
Getting started
The standard way to use Robin is through the #[derive(Job)]
macro. It works on
enum and will generate all the boilerplate needed to perform jobs.
Here is a full example:
extern crate robin; #[macro_use] extern crate serde_derive; use robin::prelude::*; #[derive(Job)] enum Jobs { #[perform_with(perform_my_job)] MyJob, } #[derive(Serialize, Deserialize, Debug, Copy, Clone)] pub struct JobArgs; fn perform_my_job(args: JobArgs, _con: &WorkerConnection) -> JobResult { println!("Job performed with {:?}", args); Ok(()) } let config = Config::default(); let worker_config = config.clone(); let con = robin::connection::establish(config, Jobs::lookup_job)?; assert_eq!(con.main_queue_size()?, 0); assert_eq!(con.retry_queue_size()?, 0); for i in 0..5 { Jobs::MyJob.perform_later(&JobArgs, &con)?; } assert_eq!(con.main_queue_size()?, 5); assert_eq!(con.retry_queue_size()?, 0); robin::worker::boot(&worker_config, Jobs::lookup_job); assert_eq!(con.main_queue_size()?, 0); assert_eq!(con.retry_queue_size()?, 0);
Normally the code the enqueues jobs and the code the boots the worker would be in separate binaries.
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. |
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 |
worker |
Contains functions for booting and running workers which perform jobs. |