pub struct MemoryBackend { /* private fields */ }Expand description
In-process backend keeping job state in a single Mutex<Vec<…>>. Drop-in
replacement for the bundled Queue storage; suitable for tests and
single-node deployments. Replace with a remote backend for multi-pod use.
Memory bound: the pending queue is capped at MemoryBackend::max_pending
(None = unlimited, default). Configure via MemoryBackend::with_max_pending
to protect against unbounded growth when producers outpace consumers.
Implementations§
Source§impl MemoryBackend
impl MemoryBackend
pub fn new() -> MemoryBackend
Sourcepub fn with_max_pending(self, max: usize) -> MemoryBackend
pub fn with_max_pending(self, max: usize) -> MemoryBackend
Cap the pending vector at max jobs. Subsequent
MemoryBackend::push calls that would exceed the cap return
BackendError::Transport with the message queue full.
Use this to bound memory growth when a misconfigured retry loop or runaway producer would otherwise fill the heap.
Source§impl MemoryBackend
impl MemoryBackend
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Number of pending jobs across every queue.
Sourcepub fn reserved_count(&self) -> usize
pub fn reserved_count(&self) -> usize
Number of currently reserved jobs.
Sourcepub fn dedup_size(&self) -> usize
pub fn dedup_size(&self) -> usize
Number of active dedup keys. Useful for diagnostics — if this grows
unboundedly your jobs are not reaching complete/dead_letter.
Sourcepub fn purge_dedup_key(&self, key: &str) -> bool
pub fn purge_dedup_key(&self, key: &str) -> bool
Drop a single dedup key out of band. Returns true if the key was
present. Use this when a long retry tail needs to be cut short and a
fresh push (same key) should be allowed to enqueue immediately.
Trait Implementations§
Source§impl Default for MemoryBackend
impl Default for MemoryBackend
Source§fn default() -> MemoryBackend
fn default() -> MemoryBackend
Source§impl QueueBackend for MemoryBackend
impl QueueBackend for MemoryBackend
Source§fn push<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
queue: &'life1 str,
payload: &'life2 [u8],
opts: PushOptions,
) -> Pin<Box<dyn Future<Output = Result<JobId, BackendError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
MemoryBackend: 'async_trait,
fn push<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
queue: &'life1 str,
payload: &'life2 [u8],
opts: PushOptions,
) -> Pin<Box<dyn Future<Output = Result<JobId, BackendError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
MemoryBackend: 'async_trait,
Source§fn reserve<'life0, 'life1, 'async_trait>(
&'life0 self,
queue: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<ReservedJob>, BackendError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MemoryBackend: 'async_trait,
fn reserve<'life0, 'life1, 'async_trait>(
&'life0 self,
queue: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<ReservedJob>, BackendError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MemoryBackend: 'async_trait,
FIFO, ready_at <= now).Source§fn complete<'life0, 'async_trait>(
&'life0 self,
id: JobId,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
'life0: 'async_trait,
MemoryBackend: 'async_trait,
fn complete<'life0, 'async_trait>(
&'life0 self,
id: JobId,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
'life0: 'async_trait,
MemoryBackend: 'async_trait,
Source§fn fail<'life0, 'async_trait>(
&'life0 self,
id: JobId,
retry_at: Option<Instant>,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
'life0: 'async_trait,
MemoryBackend: 'async_trait,
fn fail<'life0, 'async_trait>(
&'life0 self,
id: JobId,
retry_at: Option<Instant>,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
'life0: 'async_trait,
MemoryBackend: 'async_trait,
retry_at is set, requeue for that time.Source§fn dead_letter<'life0, 'async_trait>(
&'life0 self,
id: JobId,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
'life0: 'async_trait,
MemoryBackend: 'async_trait,
fn dead_letter<'life0, 'async_trait>(
&'life0 self,
id: JobId,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
'life0: 'async_trait,
MemoryBackend: 'async_trait,
Auto Trait Implementations§
impl !Freeze for MemoryBackend
impl !RefUnwindSafe for MemoryBackend
impl !UnwindSafe for MemoryBackend
impl Send for MemoryBackend
impl Sync for MemoryBackend
impl Unpin for MemoryBackend
impl UnsafeUnpin for MemoryBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more