Apalis is a simple, extensible multithreaded background job processing library for Rust.
- 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. - Fully Tokio compatible.
- Optional Web interface to help you manage your jobs.
Apalis job processing is powered by tower::Service
which means you have access to the tower
middleware.
Apalis has support for
- Redis
- SQlite
- PostgresSQL
- MySQL
- Cron Jobs
- Bring Your Own Job Source eg Twitter streams
To get started, just add to Cargo.toml
[dependencies]
apalis = { version = "0.3", features = ["redis"] }
use apalis::prelude::*;
use apalis::redis::RedisStorage;
use serde::{Deserialize, Serialize};
use anyhow::Result;
#[derive(Debug, Deserialize, Serialize)]
struct Email {
to: String,
}
async fn email_service(job: Email, _ctx: JobContext) -> Result<JobResult, JobError> {
Ok(JobResult::Success)
}
#[tokio::main]
async fn main() -> Result<()> {
std::env::set_var("RUST_LOG", "debug");
env_logger::init();
let redis = std::env::var("REDIS_URL").expect("Missing env variable REDIS_URL");
let storage = RedisStorage::new(redis).await?;
Monitor::new()
.register_with_count(2, move || {
WorkerBuilder::new(storage.clone())
.build_fn(email_service)
})
.run()
.await
}
Then
//This can be in another part of the program or another application
async fn produce_route_jobs(storage: &RedisStorage<Email>) -> Result<()> {
let mut storage = storage.clone();
storage
.push(Email {
to: "test@example.com".to_string(),
})
.await?;
}
If you are running Apalis Board, you can easily manage your jobs. See a working Rest API here
- 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 job processing
- 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
Since we provide a few storage solutions, here is a table comparing them:
Feature | Redis | Sqlite | Postgres | Sled | Mysql | Mongo | Cron |
---|---|---|---|---|---|---|---|
Scheduled jobs | β | β | β | x | β | x | β |
Retryable jobs | β | β | β | x | β | x | β |
Persistence | β | β | β | x | β | x | BYO |
Rerun Dead jobs | β | β | β | x | * | x | x |
tower
- Tower is a library of modular and reusable components for building robust networking clients and servers.- redis-rs - Redis library for rust
- sqlx - The Rust SQL Toolkit
v 0.4
- Improve monitoring
- Improve Apalis Board
- Add job progress
- Add more sources *
v 0.3
- Standardize API (Storage, Worker, Data, Middleware, Context )
- Introduce SQL
- Implement layers for Sentry and Tracing.
- Improve documentation
- Organized modules and features.
- Basic Web API Interface
- Sql Examples
- Sqlx migrations
v 0.2
- Redis Example
- Actix Web Example
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Njuguna Mureithi - Initial work - Njuguna Mureithi
See also the list of contributors who participated in this project.
It was formerly actix-redis-jobs
and if you want to use the crate name please contact me.
This project is licensed under the MIT License - see the LICENSE.md file for details
- Inspiration: The redis part of this project is heavily inspired by Curlyq which is written in GoLang