Crate apalis

Source
Expand description

apalis is a simple, extensible multithreaded background job processing library for rust.

§Core Features

  • Simple and predictable functional job handling model with a macro free API.
  • Takes full advantage of the tower ecosystem of middleware, services, and utilities.
  • Anything that implements Stream can be used as a job source.
  • Runtime agnostic with inbuilt support for tokio and async-std.
  • Provides high concurrency, and allows for configuration of workers, jobs and thread pool.

An apalis job is powered by a tower Service which means you have access to the tower middleware.

§Example

use apalis::prelude::*;
use serde::{Deserialize, Serialize};
use apalis_redis::{RedisStorage, Config};

#[derive(Debug, Deserialize, Serialize)]
struct Email {
    to: String,
}

async fn send_email(job: Email, data: Data<usize>) -> Result<(), Error> {
    Ok(())
}

#[tokio::main]
async fn main() {
    let redis = std::env::var("REDIS_URL").expect("Missing REDIS_URL env variable");
    let conn = apalis_redis::connect(redis).await.unwrap();
    let storage = RedisStorage::new(conn);
    Monitor::new()
        .register({
            WorkerBuilder::new(&format!("quick-sand"))
                .concurrency(2)
                .data(0usize)
                .backend(storage.clone())
                .build_fn(send_email)
        })
        .run()
        .await
        .unwrap();
}

§Web UI Available

UI See this example

§Feature flags

  • tracing (enabled by default) — Support Tracing 👀
  • sentry — Support for Sentry exception and performance monitoring
  • prometheus — Support Prometheus metrics
  • retry — Support direct retrying jobs
  • timeout — Support timeouts on jobs
  • limit — 💪 Limit the amount of jobs
  • filter — Support filtering jobs based on a predicate
  • catch-panic — Captures panics in executions and convert them to errors

Modules§

layers
apalis fully supports middleware via Layer
prelude
Common imports