/batch-rs

Background job library for Rust supporting RabbitMQ

Primary LanguageRustApache License 2.0Apache-2.0

Batch Crates.io API Docs Travis Build Status Appveyor Build status

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.

Installation

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;

Batch in action

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.

Features

  • codegen: (enabled by default): Enables the use of the job procedural macro.

License

Licensed under either of

at your option.

Contribution

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.