pub struct MemBroker { /* private fields */ }Expand description
In-memory broker with a global queue and per-task queues.
Not suitable for production — all data is lost on process exit. Useful for unit tests and local development.
§Queue semantics
- [
route_invocation]: pushes to the global queue (task ID unknown at call site). - [
route_invocation_for_task]: pushes to a task-specific queue; used by callers that know the task ID (e.g.RustvelloApp::submit_call). - [
retrieve_invocation] withNone: drains the global queue first, then falls back to any non-empty task queue (round-robin); ensures that invocations routed via the task-aware path are also visible to runners that poll without a filter. - [
retrieve_invocation] withSome(task_id): drains only the task-specific queue.
§Notify-based wakeup
Workers can call [wait_for_work] instead of polling with sleep.
When new work is routed, one waiting worker is woken via tokio::sync::Notify.
Implementations§
Trait Implementations§
Source§impl Broker for MemBroker
impl Broker for MemBroker
Source§fn route_invocation<'life0, 'life1, 'async_trait>(
&'life0 self,
invocation_id: &'life1 InvocationId,
) -> Pin<Box<dyn Future<Output = RustvelloResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn route_invocation<'life0, 'life1, 'async_trait>(
&'life0 self,
invocation_id: &'life1 InvocationId,
) -> Pin<Box<dyn Future<Output = RustvelloResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Route to the global queue (task ID unknown at this call site).
Source§fn route_invocation_for_task<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
invocation_id: &'life1 InvocationId,
task_id: &'life2 TaskId,
) -> Pin<Box<dyn Future<Output = RustvelloResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn route_invocation_for_task<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
invocation_id: &'life1 InvocationId,
task_id: &'life2 TaskId,
) -> Pin<Box<dyn Future<Output = RustvelloResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Route to the task-specific queue.
Callers that know the task ID should prefer this over route_invocation
so that retrieve_invocation(Some(task_id)) can return a filtered result.
Source§fn retrieve_invocation_for_language<'life0, 'life1, 'async_trait>(
&'life0 self,
language: &'life1 str,
) -> Pin<Box<dyn Future<Output = RustvelloResult<Option<InvocationId>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn retrieve_invocation_for_language<'life0, 'life1, 'async_trait>(
&'life0 self,
language: &'life1 str,
) -> Pin<Box<dyn Future<Output = RustvelloResult<Option<InvocationId>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Retrieve from queues matching a specific language.
Behavior: First checks the global queue, then per-task queues
whose keys start with "language::". Because the global queue is
checked first, a single-language worker can drain globally-routed
invocations before language-agnostic workers see them.
Queue keys for foreign tasks use the format "language::module.name",
so we match keys that start with "language::". For local tasks
(no language prefix), they are only retrieved if language is empty.
Source§fn retrieve_invocations<'life0, 'life1, 'async_trait>(
&'life0 self,
max: usize,
task_id: Option<&'life1 TaskId>,
) -> Pin<Box<dyn Future<Output = RustvelloResult<Vec<InvocationId>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn retrieve_invocations<'life0, 'life1, 'async_trait>(
&'life0 self,
max: usize,
task_id: Option<&'life1 TaskId>,
) -> Pin<Box<dyn Future<Output = RustvelloResult<Vec<InvocationId>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Batch retrieval: single lock acquisition drains up to max items.
Source§fn wait_for_work<'life0, 'life1, 'async_trait>(
&'life0 self,
cancel: &'life1 CancellationToken,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn wait_for_work<'life0, 'life1, 'async_trait>(
&'life0 self,
cancel: &'life1 CancellationToken,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Zero-cost wait: blocks until new work is routed or cancelled.
Source§fn retrieve_invocation<'life0, 'life1, 'async_trait>(
&'life0 self,
task_id: Option<&'life1 TaskId>,
) -> Pin<Box<dyn Future<Output = RustvelloResult<Option<InvocationId>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn retrieve_invocation<'life0, 'life1, 'async_trait>(
&'life0 self,
task_id: Option<&'life1 TaskId>,
) -> Pin<Box<dyn Future<Output = RustvelloResult<Option<InvocationId>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
None if the queue is empty.