extern crate closer; extern crate env_logger; extern crate r2d2; extern crate r2d2_redis; extern crate resque; use r2d2::{Config, Pool, PooledConnection}; use r2d2_redis::RedisConnectionManager; use resque::{Result, ResultExt, WithRedis}; type RedisPool = Pool; type RedisConn = PooledConnection; // RUST_LOG=debug cargo run --example hello_schedule fn main() { env_logger::init().unwrap(); let closer = closer::Closer::init(); let with_redis = HelloWithRedis::new("redis://127.0.0.1:6379/0"); let config = resque::ScheduleConfig::new(with_redis, closer.closed()); resque::start_schedule(config).unwrap(); } #[derive(Clone)] struct HelloWithRedis(RedisPool); impl HelloWithRedis { fn new(redis_url: &str) -> HelloWithRedis { let manager = RedisConnectionManager::new(redis_url).unwrap(); let pool = Pool::new(Config::default(), manager).unwrap(); HelloWithRedis(pool) } } impl WithRedis for HelloWithRedis { type Conn = RedisConn; fn with_redis(&self, f: F) -> Result where F: FnOnce(&Self::Conn) -> Result, { let redis_conn = self.0.get().chain_err(|| "could not get redis conn")?; f(&redis_conn) } }