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;

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

impl Job for Email {
    const NAME: &'static str = "apalis::Email";
}

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::<TokioExecutor>::new()
        .register_with_count(2, {
            WorkerBuilder::new(&format!("quick-sand"))
                .data(0usize)
                .source(storage.clone())
                .build_fn(send_email)
        })
        .run()
        .await
        .unwrap();
}

§Web UI Available

UI See this example

§Feature flags

  • redis — Include redis storage
  • postgres — Include Postgres storage
  • sqlite — Include SQlite storage
  • mysql — Include MySql storage
  • cron — Include Cron functionality
  • 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
  • async-std-comp — Compatibility with async-std and smol runtimes
  • tokio-comp (enabled by default) — Compatibility with tokio and actix runtimes

Modules§

  • croncron
    Include Cron utilities
  • apalis fully supports middleware via Layer
  • mysqlmysql
    Include the default MySQL storage
  • postgrespostgres
    Include the default Postgres storage
  • Common imports
  • redisredis
    Include the default Redis storage
  • sqlitesqlite
    Include the default Sqlite storage
  • Utilities for working with apalis