Skip to main content

nest_rs_queue/
consumer.rs

1//! Consumer seam.
2//!
3//! A backend's [`JobConsumer`] receives the boot-time list of
4//! [`ProcessMethod`]s reachable in this app and runs until the shutdown
5//! signal fires. Filtering by
6//! [`ReachableProviders`](::nest_rs_core::ReachableProviders) happens **before**
7//! `run` — the backend just dispatches.
8
9use async_trait::async_trait;
10use nest_rs_core::Container;
11use tokio_util::sync::CancellationToken;
12
13use crate::inventory::ProcessMethod;
14
15/// Drains a list of `#[process]` methods until cancellation. One per app —
16/// the `Transport` a queue backend contributes typically wraps a
17/// [`JobConsumer`] and forwards the cancellation token.
18#[async_trait]
19pub trait JobConsumer: Send + Sync + 'static {
20    /// Run the consumer loop. `methods` is the access-graph-filtered set of
21    /// process methods this backend is responsible for; `container` resolves
22    /// the providers each handler dispatches into; `cancel` triggers
23    /// graceful shutdown.
24    async fn run(
25        self: Box<Self>,
26        methods: Vec<&'static ProcessMethod>,
27        container: Container,
28        cancel: CancellationToken,
29    ) -> anyhow::Result<()>;
30}