apalis/
lib.rs

1#![warn(
2    missing_debug_implementations,
3    missing_docs,
4    rust_2018_idioms,
5    unreachable_pub
6)]
7#![cfg_attr(docsrs, feature(doc_cfg))]
8//! apalis is a simple, extensible multithreaded background job processing library for rust.
9//! ## Core Features
10//! - Simple and predictable functional job handling model with a macro free API.
11//! - Takes full advantage of the [`tower`] ecosystem of
12//!   middleware, services, and utilities.
13//! - Anything that implements [`Stream`] can be used as a job source.
14//! - Runtime agnostic with inbuilt support for tokio and async-std.
15//! - Provides high concurrency, and allows for configuration of workers, jobs and thread pool.
16//!
17//! An apalis job is powered by a tower [`Service`] which means you have access to the [`tower`] middleware.
18//!  ### Example
19//! ```rust, no_run
20//! use apalis::prelude::*;
21//! use serde::{Deserialize, Serialize};
22//! use apalis_redis::{RedisStorage, Config};
23//!
24//! #[derive(Debug, Deserialize, Serialize)]
25//! struct Email {
26//!     to: String,
27//! }
28//!
29//! async fn send_email(job: Email, data: Data<usize>) -> Result<(), Error> {
30//!     Ok(())
31//! }
32//!
33//! #[tokio::main]
34//! async fn main() {
35//!     let redis = std::env::var("REDIS_URL").expect("Missing REDIS_URL env variable");
36//!     let conn = apalis_redis::connect(redis).await.unwrap();
37//!     let storage = RedisStorage::new(conn);
38//!     Monitor::new()
39//!         .register({
40//!             WorkerBuilder::new(&format!("quick-sand"))
41//!                 .concurrency(2)
42//!                 .data(0usize)
43//!                 .backend(storage.clone())
44//!                 .build_fn(send_email)
45//!         })
46//!         .run()
47//!         .await
48//!         .unwrap();
49//! }
50//!```
51//!
52//! ## Web UI Available
53//! ![UI](https://github.com/geofmureithi/apalis-board/raw/master/screenshots/workers.png)
54//! See [this example](https://github.com/geofmureithi/apalis/tree/main/examples/rest-api)
55//! ## Feature flags
56#![cfg_attr(
57    feature = "docsrs",
58    cfg_attr(doc, doc = ::document_features::document_features!())
59)]
60//!
61//! [`Service`]: https://docs.rs/tower/latest/tower/trait.Service.html
62//! [`tower`]: https://crates.io/crates/tower
63//! [`tower-http`]: https://crates.io/crates/tower-http
64//! [`Layer`]: https://docs.rs/tower/latest/tower/trait.Layer.html
65//! [`Stream`]: https://docs.rs/futures/latest/futures/stream/trait.Stream.html
66/// apalis fully supports middleware via [`Layer`](https://docs.rs/tower/latest/tower/trait.Layer.html)
67pub mod layers;
68
69/// Common imports
70pub mod prelude {
71    pub use crate::layers::WorkerBuilderExt;
72    pub use apalis_core::{
73        backend::Backend,
74        backend::BackendExpose,
75        backend::Stat,
76        backend::WorkerState,
77        builder::{WorkerBuilder, WorkerFactory, WorkerFactoryFn},
78        codec::Codec,
79        data::Extensions,
80        error::{BoxDynError, Error},
81        layers::extensions::{AddExtension, Data},
82        memory::{MemoryStorage, MemoryWrapper},
83        monitor::Monitor,
84        mq::MessageQueue,
85        notify::Notify,
86        poller::stream::BackendStream,
87        poller::{controller::Controller, Poller},
88        request::State,
89        request::{Request, RequestStream},
90        response::IntoResponse,
91        service_fn::{service_fn, FromRequest, ServiceFn},
92        step::*,
93        storage::Storage,
94        task::attempt::Attempt,
95        task::task_id::TaskId,
96        worker::{Context, Event, Ready, Worker, WorkerError, WorkerId},
97    };
98}