kiomq/lib.rs
1#![doc = include_str!("../README.md")]
2#![warn(
3 missing_debug_implementations,
4 missing_docs,
5 clippy::pedantic,
6 clippy::nursery
7)]
8#![cfg_attr(docsrs, feature(doc_cfg))]
9mod error;
10mod events;
11mod job;
12/// Re-exports of test helpers for verifying custom [`Store`] implementations.
13pub mod macros;
14mod queue;
15mod stores;
16mod timers;
17mod utils;
18mod worker;
19pub use async_backtrace::frame;
20/// Attribute macro that wraps an `async fn` so it appears in
21/// [`async_backtrace`](https://docs.rs/async-backtrace) stack traces.
22///
23/// Apply `#[framed]` to your processor function to get richer async backtraces
24/// when a panic or error occurs inside a job. The worker already catches panics
25/// and converts them to failures, but having the full async call stack in the
26/// trace makes debugging much easier.
27///
28/// # Example
29///
30/// ```rust
31/// use std::sync::Arc;
32/// use kiomq::{framed, InMemoryStore, Job, KioError, Queue, Store, Worker, WorkerOpts};
33///
34/// #[framed]
35/// async fn my_processor<S: Store<u64, u64, ()>>(
36/// _store: Arc<S>,
37/// job: Job<u64, u64, ()>,
38/// ) -> Result<u64, KioError> {
39/// let data = job.data.unwrap_or_default();
40/// if data == 0 {
41/// // Returning Err marks the job as failed and triggers a retry
42/// // (up to `attempts` times, as configured in QueueOpts / JobOptions).
43/// return Err(std::io::Error::new(std::io::ErrorKind::Other, "zero input").into());
44/// }
45/// Ok(data * 2)
46/// }
47///
48/// # #[tokio::main]
49/// # async fn main() -> kiomq::KioResult<()> {
50/// # let store: InMemoryStore<u64, u64, ()> = InMemoryStore::new(None, "framed-demo");
51/// # let queue = Queue::new(store, None).await?;
52/// # let worker = Worker::new_async(&queue, |s, j| my_processor(s, j), Some(WorkerOpts::default()))?;
53/// # worker.run()?;
54/// # worker.close();
55/// # Ok(())
56/// # }
57/// ```
58pub use async_backtrace::framed;
59#[cfg(feature = "redis-store")]
60pub use deadpool_redis::Config;
61pub use error::*;
62pub(crate) use events::EventEmitter;
63pub use events::EventParameters;
64pub use job::*;
65pub use queue::*;
66pub use stores::*;
67pub use timers::{TimedMap, Timer};
68#[cfg(feature = "redis-store")]
69pub use utils::{fetch_redis_pass, get_queue_metrics};
70pub use worker::{Worker, WorkerMetrics, WorkerOpts};
71
72/// Convenience alias for `Result<T, KioError>`.
73pub type KioResult<T> = Result<T, KioError>;