1 unstable release

Uses old Rust 2015

0.1.0 Feb 20, 2018

#16 in #background-jobs


Used in batch

MIT/Apache

7KB
112 lines

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.


lib.rs:

This crate provides a Batch's derive macro.

#[derive(Task)]

Dependencies

~2MB
~46K SLoC