tower
] ecosystem of
middleware, services, and utilities.apalis job processing is powered by [tower::Service
] which means you have access to the [tower
] middleware.
apalis has support for:
| Source | Crate | Example |
| ----------- | ----------- | --------- |
| Cron Jobs | |
| Redis |
|
| Sqlite |
|
| Postgres |
|
| MySQL |
|
| Amqp |
|
| From Scratch |
| |
To get started, just add to Cargo.toml
toml
[dependencies]
apalis = { version = "0.4", features = ["redis"] }
```rust use apalis::prelude::*; use apalis::redis::RedisStorage; use serde::{Deserialize, Serialize}; use anyhow::Result;
struct Email { to: String, }
impl Job for Email { const NAME: &'static str = "apalis::Email"; }
async fn email_service(job: Email, ctx: JobContext) { info!("Do something"); }
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 |index| { WorkerBuilder::new(format!("email-worker-{index}")) .withstorage(storage.clone()) .buildfn(emailservice) }) .run() .await }
```
Then
```rust
//This can be in another part of the program or another application eg a http server
async fn produceroutejobs(storage: &RedisStorage
```
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 |
```mermaid sequenceDiagram participant App participant Worker participant Producer
App->>+Producer: Add job to queue
Producer-->>+Worker: Job data
Worker->>+Producer: Update job status to 'running' via Layer
Producer-->>-Worker: Confirmation
Worker->>+App: Notify job started via Layer
loop job execution
Worker-->>-App: Report job progress via Layer
end
Worker->>+Producer: Update job status to 'completed' via Layer
```
If you are running apalis Board, you can easily manage your jobs. See a working rest API example here
tower
] - Tower is a library of modular and reusable components for building robust networking clients and servers.v 1.0 - [ ] Refactor the crates structure - [ ] Mocking utilities - [ ] Support for SurrealDB and Mongo - [ ] Lock free for Postgres - [ ] Add more utility layers - [ ] Use extractors in job fn structure - [ ] Polish up documentation - [ ] Improve and standardize apalis Board - [ ] Benchmarks
v 0.4
v 0.3
v 0.2
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.
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details