apalis_core/worker/ext/
mod.rs

1//! Extension traits for building and extending workers
2//!
3//! Extension traits can be used for enhancing worker builder functionality that is not provided by default.
4//!
5//! # Available extension traits
6//!
7//! The available extensions include:
8//!
9//! - [`ack`]: Traits and utilities for acknowledging task completion.
10//! - [`event_listener`]: Traits for subscribing to and handling worker events.
11//! - [`long_running`]: Traits for building long running workers and tasks.
12//! - [`circuit_breaker`]: Traits for adding circuit breaker patterns to workers.
13//! - [`parallelize`]: Traits for enabling parallel task execution within workers.
14//!
15//! These extensions can be composed to customize worker behavior, improve reliability, and add observability.
16//!
17//! ## Creating a custom Worker extension trait
18//!
19//! The goal of using extension traits is to provide a way to add custom methods to the `WorkerBuilder` struct.
20//! These methods can encapsulate common configurations or patterns that you want to reuse across different workers.
21//! This example demonstrates how to define and implement an extension trait for `WorkerBuilder`.
22//!
23//! ```rust,ignore
24//! # use apalis_core::worker::builder::WorkerBuilder;
25//! # use apalis_core::backend::memory::MemoryStorage;
26//! /// Example extension trait for WorkerBuilder that adds a custom method.
27//! pub trait MakeSuperFastExt<Args, Ctx, Backend, Middleware>: Sized {
28//!     /// Adds custom behavior to the WorkerBuilder.
29//!     fn with_super_fast(self) -> WorkerBuilder<Args, Ctx, Backend, Middleware>;
30//! }
31//!
32//! impl<Args, Ctx, Backend, Middleware> MakeSuperFastExt<Args, Ctx, Backend, Middleware>
33//!     for WorkerBuilder<Args, Ctx, Backend, Middleware>
34//! {
35//!     fn with_super_fast(self) -> WorkerBuilder<Args, Ctx, Backend, Middleware> {
36//!         // Insert your custom logic here
37//!         // Do something with self, e.g., modify configuration, add middleware, etc.
38//!         // The method can also accept parameters if needed, e.g., specific configuration options
39//!         self
40//!     }
41//! }
42//! #    async fn task(task: u32) {
43//! #        println!("Processing task: {task}");
44//! #    }
45//! # let in_memory: MemoryStorage<()> = MemoryStorage::new();
46//! // Usage
47//! let builder = WorkerBuilder::new("my_worker")
48//!     .backend(in_memory)
49//!     .with_super_fast()
50//!     .build(task);
51//! ```
52//! If your functionality is useful, consider contributing it as the `apalis-{my-functionality}-ext` crate and publishing it on crates.io.
53pub mod ack;
54pub mod circuit_breaker;
55pub mod event_listener;
56pub mod long_running;
57pub mod parallelize;