Skip to main content

BatchQueue

Struct BatchQueue 

Source
pub struct BatchQueue<D>
where D: Clone + Send + Sync + Serialize + 'static,
{ /* private fields */ }
Expand description

In-memory batch queue with model-aware reordering and ETA estimation.

The queue automatically groups jobs by resource_key to minimize expensive resource swaps (e.g. GPU model loads). It also tracks per-item processing durations bucketed by size for accurate ETA predictions.

Implementations§

Source§

impl<D> BatchQueue<D>
where D: Clone + Send + Sync + Serialize + 'static,

Source

pub fn new() -> Self

Create a new empty batch queue.

Source

pub fn with_scheduling(scheduling: SchedulingConfig) -> Self

Create a new queue with explicit scheduling controls.

Source

pub fn enqueue(&self, job: BatchJob<D>) -> Result<String>

Add a new batch job and perform resource-aware reordering. Returns the assigned job ID.

Source

pub fn next_queued(&self) -> Option<BatchJob<D>>

Get the next queued job (without removing it).

Source

pub fn mark_running(&self, job_id: &str) -> Result<()>

Mark a job as running and set its started_at timestamp.

Both the job status and scheduling metadata are updated while holding the jobs lock, ensuring they cannot become inconsistent (ABQ-2 fix: previously the jobs lock was dropped before the scheduling locks were acquired).

Source

pub fn update_item( &self, job_id: &str, item_id: &str, status: BatchItemStatus, error: Option<String>, duration_ms: Option<u64>, ) -> Result<()>

Update a single item’s status within a job.

If the item completed successfully and duration_ms is provided, the ETA tracker is automatically updated with the new data point.

Source

pub fn mark_completed( &self, job_id: &str, ) -> Result<Option<BatchCompletionSummary>>

Mark a job as completed and produce a completion summary.

Automatically determines whether it’s Completed or CompletedWithErrors based on item statuses.

Source

pub fn cancel_item(&self, job_id: &str, item_id: &str) -> Result<()>

Cancel a single pending item within a job.

Source

pub fn cancel_job(&self, job_id: &str) -> Result<()>

Cancel an entire batch job. Running items finish; pending items are cancelled.

Source

pub fn retry_failed(&self, job_id: &str) -> Result<()>

Retry all failed items in a completed job by resetting them to Pending. The job is re-queued and reordering is applied.

Retry lineage: each retried item keeps its existing attempt_id (same logical retry family) but clears its trial_id so the executor will mint a fresh one on the next execution. This keeps batch-item retries distinguishable from outer job-level retries.

Source

pub fn list_jobs(&self) -> Vec<BatchJob<D>>

Get all jobs (cloned snapshot).

Source

pub fn get_job(&self, job_id: &str) -> Option<BatchJob<D>>

Get a specific job by ID.

Source

pub fn estimate_remaining_ms(&self, job_id: &str) -> Option<u64>

Estimate remaining processing time for a job in milliseconds. Returns None if no historical data is available.

Source

pub fn estimate_remaining(&self, job_id: &str) -> Option<EtaEstimate>

Estimate remaining processing time with confidence and sample metadata.

Source

pub fn has_running_job(&self) -> bool

Check if any batch job is currently running.

Source

pub fn eta_sample_count( &self, resource_key: &str, operation: &str, size_bucket: SizeBucket, ) -> u64

Get the number of ETA samples for a specific resource/operation/size combination.

Source

pub fn queued_count(&self) -> usize

Get the number of queued (waiting) jobs.

Trait Implementations§

Source§

impl<D> Default for BatchQueue<D>
where D: Clone + Send + Sync + Serialize + 'static,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<D> !Freeze for BatchQueue<D>

§

impl<D> RefUnwindSafe for BatchQueue<D>

§

impl<D> Send for BatchQueue<D>

§

impl<D> Sync for BatchQueue<D>

§

impl<D> Unpin for BatchQueue<D>
where D: Unpin,

§

impl<D> UnsafeUnpin for BatchQueue<D>

§

impl<D> UnwindSafe for BatchQueue<D>

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, 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