Simple and reliable background processing for Rust using Actix and Redis
To get started, just add to Cargo.toml
toml
[dependencies]
actix-redis-jobs = { version = "0.2.0-beta-0" }
A running redis server is required. You can quickly use docker:
bash
docker run --name some-redis -d redis
```rust use actix::prelude::*; use log::info; use serde::{Deserialize, Serialize}; use futures::future::BoxFuture;
use actixredisjobs::{ JobContext, JobHandler, JobResult, Producer, RedisConsumer, RedisStorage, ScheduleJob, WorkManager, };
enum Math { Sum(isize, isize), Multiply(isize, isize), }
impl JobHandler for Math {
fn handle(&self, _ctx: &JobContext) -> BoxFuture
async fn main() { std::env::setvar("RUSTLOG", "info"); envlogger::init(); let storage = RedisStorage::new("redis://127.0.0.1/"); let producer = Producer::start(&storage, "math"); let sum = Math::Sum(1, 2); let multiply = Math::Multiply(9, 8); let scheduled = ScheduleJob::new(sum).inminutes(1); producer.dosend(scheduled); producer.dosend(multiply);
WorkManager::create(move |worker| {
worker.consumer(RedisConsumer::<Math>::new(&storage, "math").workers(2))
})
.run()
.await;
} ```
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details