nest_rs_queue_macros/lib.rs
1//! The `#[processor]` decorator, re-exported by `nestrs-queue` (the
2//! backend-agnostic abstractions crate) so the call site keeps writing
3//! `use nest_rs_queue::processor;` regardless of which backend integration
4//! (nestrs-redis, …) is wired in.
5
6use proc_macro::TokenStream;
7
8mod processor;
9
10/// Orchestrator on an `#[injectable]` provider's `impl` block. Each method
11/// tagged with `#[process(queue = "...", concurrency, retries)]` becomes a
12/// queue consumer the `QueueWorker` spawns at boot.
13///
14/// A single provider may carry several `#[process]` methods (different
15/// queues, different concurrencies) sharing the same `#[inject]`
16/// dependencies — pooling related queue handlers on one service keeps
17/// shared state (clients, repositories) in one place.
18///
19/// Per-method attributes (exactly one `#[process]` per method):
20///
21/// - `#[process(queue = "audio")]` — minimal, defaults `concurrency = 1`,
22/// `retries = 0`.
23/// - `#[process(queue = "audio", concurrency = 5)]` — bound the in-flight jobs
24/// per worker.
25/// - `#[process(queue = "audio", concurrency = 5, retries = 3)]` — apalis
26/// retries before the job lands on the queue's failed list.
27///
28/// The method signature is `async fn(&self, job: T) -> anyhow::Result<()>`,
29/// where `T: Job`. The macro extracts the job type from the second
30/// parameter, generates a typed handler, and submits a per-method
31/// inventory entry the worker drains.
32#[proc_macro_attribute]
33pub fn processor(args: TokenStream, input: TokenStream) -> TokenStream {
34 processor::processor(args, input)
35}