A background job library written in Rust.
Batch allows you to defer jobs to worker processes, by sending messages to a broker. It is a type-safe library that favors safety over performance in order to minimize risk and avoid mistakes. It is completely asynchronous and is based on the tokio
runtime.
Minimum Rust Version: 1.31
Add this to your Cargo.toml
:
[dependencies]
batch = "0.2"
Only if you're using Rust 2015 edition
Then add this to your crate root:
extern crate batch;
use batch::job;
use batch_rabbitmq::{queues, Connection};
use std::path::PathBuf;
use tokio::prelude::Future;
queues! {
Transcoding {
name = "transcoding",
bindings = [
self::transcode,
]
}
}
#[job(name = "batch-example.transcode")]
fn transcode(path: PathBuf) {
// ...
}
fn main() {
let fut = Connection::build("amqp://guest:guest@localhost:5672/%2f")
.declare(Transcoding)
.connect()
.and_then(|mut client| {
let job = transcode("./video.mp4".into());
Transcoding(job).dispatch(&mut client)
})
.map_err(|e| eprintln!("An error occured: {}", e));
tokio::run(fut);
}
More examples are available on GitHub and in the guide.
codegen
: (enabled by default): Enables the use of thejob
procedural macro.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.