Expand description
Apalis is a simple, extensible multithreaded background job processing library for Rust.
Core Features
- Simple and predictable job handling model.
- Jobs handlers with a macro free API.
- Take full advantage of the
tower
ecosystem of middleware, services, and utilities. - Takes full advantage of the actor model with each worker being an [
Actor
]. - Bring your own Storage.
Apalis job processing is powered by tower::Service
which means you have access to the tower
and tower-http
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, ctx: JobContext) -> Result<JobResult, JobError> {
Ok(JobResult::Success)
}
#[tokio::main]
async fn main() -> std::io::Result<()> {
let redis = std::env::var("REDIS_URL").expect("Missing REDIS_URL env variable");
let storage = RedisStorage::connect(redis).await.expect("Storage failed");
Monitor::new()
.register_with_count(2, move |_| {
WorkerBuilder::new(storage.clone())
.build_fn(send_email)
})
.run()
.await
}
Web UI Available
See this example
Feature flags
-
tracing
(enabled by default) — Support Tracing 👀 -
redis
— Include redis storage -
postgres
— Include Postgres storage -
sqlite
— Include SQlite storage -
mysql
— Include MySql storage -
cron
— Include Cron functionality -
storage
— Include Storage utils, and build your own -
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 -
extensions
— Add a global extensions to jobs -
redis-pubsub
— Publish and listen worker events via Redis pubsub -
broker
— Support event collection, communication between workers.