Skip to main content

MemBroker

Struct MemBroker 

Source
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] with None: 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] with Some(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§

Source§

impl MemBroker

Source

pub fn new() -> Self

Trait Implementations§

Source§

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,

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,

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,

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,

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,

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,

Retrieve the next invocation to process. Returns None if the queue is empty.
Source§

fn count_invocations<'life0, 'life1, 'async_trait>( &'life0 self, task_id: Option<&'life1 TaskId>, ) -> Pin<Box<dyn Future<Output = RustvelloResult<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Count queued invocations, optionally filtered by task.
Source§

fn purge<'life0, 'life1, 'async_trait>( &'life0 self, task_id: Option<&'life1 TaskId>, ) -> Pin<Box<dyn Future<Output = RustvelloResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Remove all queued invocations.
Source§

fn route_invocations<'life0, 'life1, 'async_trait>( &'life0 self, ids: &'life1 [InvocationId], ) -> Pin<Box<dyn Future<Output = Result<(), RustvelloError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Queue multiple invocations at once (batch optimization).
Source§

impl Default for MemBroker

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more