apalis Build Status

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

Features

apalis job processing is powered by [tower::Service] which means you have access to the [tower] middleware.

apalis has support for

Getting Started

To get started, just add to Cargo.toml

toml [dependencies] apalis = { version = "0.4", features = ["redis"] }

Usage

```rust 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) { info!("Do something"); }

[tokio::main]

async fn main() -> Result<()> { std::env::setvar("RUSTLOG", "debug"); envlogger::init(); let redis = std::env::var("REDISURL").expect("Missing env variable REDISURL"); let storage = RedisStorage::new(redis).await?; Monitor::new() .registerwithcount(2, move || { WorkerBuilder::new("email-worker-1") .withstorage(storage.clone()) .buildfn(emailservice) }) .run() .await }

```

Then

```rust //This can be in another part of the program or another application async fn produceroutejobs(storage: &RedisStorage) -> Result<()> { let mut storage = storage.clone(); storage .push(Email { to: "test@example.com".to_string(), }) .await?; }

```

Web UI

If you are running apalis Board, you can easily manage your jobs. See a working Rest API here

UI

Feature flags

Storage Comparison

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 | ✓ | | Retry jobs | ✓ | ✓ | ✓ | x | ✓ | x | ✓ | | Persistence | ✓ | ✓ | ✓ | x | ✓ | x | BYO | | Rerun Dead jobs | ✓ | ✓ | ✓ | x | ✓ | x | x |

How apalis works (Draft)

```mermaid sequenceDiagram participant App participant Worker participant Postgres

App->>+Worker: Add job to queue
Worker->>+Postgres: Poll queue for job
Postgres-->>-Worker: Job data
Worker->>+Postgres: Update job status to 'running'
Postgres-->>-Worker: Confirmation
Worker->>+App: Notify job started
loop job execution
    Worker-->>-App: Report job progress
end
Worker->>+Postgres: Update job status to 'completed'
Postgres-->>-Worker: Confirmation
Worker->>+App: Notify job completed

```

Thanks to

Roadmap

v 0.4

v 0.3

v 0.2

Resources

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

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.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments