Skip to main content

Scheduler

Struct Scheduler 

Source
pub struct Scheduler<T> { /* private fields */ }
Expand description

Multi-tenant in-process scheduler with DRR fairness and explicit backpressure.

Implementations§

Source§

impl<T> Scheduler<T>

Source

pub fn set_tenant_quantum(&self, tenant: TenantKey, quantum: u64)

Sets a static DRR quantum override for a tenant.

Source

pub fn clear_tenant_quantum(&self, tenant: TenantKey)

Removes a static DRR quantum override for a tenant.

Source

pub fn set_quantum_provider( &self, provider: Option<Arc<dyn Fn(TenantKey) -> u64 + Send + Sync>>, )

Sets or clears the dynamic per-tenant quantum provider.

Source

pub fn new(config: SchedulerConfig) -> Scheduler<T>

Creates a scheduler with the provided configuration.

Source

pub fn enqueue(&self, tenant: TenantKey, task: Task<T>) -> EnqueueResult

Enqueues a task without returning a cancel handle.

Source

pub fn enqueue_with_handle( &self, tenant: TenantKey, task: Task<T>, ) -> EnqueueWithHandleResult

Enqueues a task and returns a TaskHandle that can be cancelled.

Source

pub fn cancel(&self, handle: TaskHandle) -> CancelResult

Cancels a pending task identified by handle.

Cancellation is best-effort for pending work and does not affect tasks that have already been dequeued for execution.

Source

pub fn try_dequeue(&self) -> DequeueResult<T>

Attempts to dequeue one task without blocking.

Source

pub fn dequeue_blocking(&self) -> DequeueResult<T>

Dequeues one task, blocking until work is available or scheduler closes.

Source

pub fn dequeue_blocking_timeout(&self, timeout: Duration) -> DequeueResult<T>

Dequeues one task, waiting at most timeout.

Returns DequeueResult::Empty on timeout when the scheduler is still open.

Source

pub fn stats(&self) -> SchedulerStats

Returns a snapshot of current scheduler metrics.

Source

pub fn close(&self)

Source

pub fn close_immediate(&self)

Closes immediately: stops accepting new work and wakes blocked consumers.

Source

pub fn close_drain(&self)

Closes in drain mode: stops accepting and drains queued work before closing.

Source

pub fn close_with_mode(&self, mode: CloseMode)

Closes using the provided mode.

Auto Trait Implementations§

§

impl<T> !Freeze for Scheduler<T>

§

impl<T> !RefUnwindSafe for Scheduler<T>

§

impl<T> Send for Scheduler<T>
where T: Send,

§

impl<T> Sync for Scheduler<T>
where T: Send,

§

impl<T> Unpin for Scheduler<T>
where T: Unpin,

§

impl<T> !UnwindSafe for Scheduler<T>

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