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>
impl<T> Scheduler<T>
Sourcepub fn set_tenant_quantum(&self, tenant: TenantKey, quantum: u64)
pub fn set_tenant_quantum(&self, tenant: TenantKey, quantum: u64)
Sets a static DRR quantum override for a tenant.
Sourcepub fn clear_tenant_quantum(&self, tenant: TenantKey)
pub fn clear_tenant_quantum(&self, tenant: TenantKey)
Removes a static DRR quantum override for a tenant.
Sourcepub fn set_quantum_provider(
&self,
provider: Option<Arc<dyn Fn(TenantKey) -> u64 + Send + Sync>>,
)
pub fn set_quantum_provider( &self, provider: Option<Arc<dyn Fn(TenantKey) -> u64 + Send + Sync>>, )
Sets or clears the dynamic per-tenant quantum provider.
Sourcepub fn new(config: SchedulerConfig) -> Scheduler<T>
pub fn new(config: SchedulerConfig) -> Scheduler<T>
Creates a scheduler with the provided configuration.
Sourcepub fn enqueue(&self, tenant: TenantKey, task: Task<T>) -> EnqueueResult
pub fn enqueue(&self, tenant: TenantKey, task: Task<T>) -> EnqueueResult
Enqueues a task without returning a cancel handle.
Sourcepub fn enqueue_with_handle(
&self,
tenant: TenantKey,
task: Task<T>,
) -> EnqueueWithHandleResult
pub fn enqueue_with_handle( &self, tenant: TenantKey, task: Task<T>, ) -> EnqueueWithHandleResult
Enqueues a task and returns a TaskHandle that can be cancelled.
Sourcepub fn cancel(&self, handle: TaskHandle) -> CancelResult
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.
Sourcepub fn try_dequeue(&self) -> DequeueResult<T>
pub fn try_dequeue(&self) -> DequeueResult<T>
Attempts to dequeue one task without blocking.
Sourcepub fn dequeue_blocking(&self) -> DequeueResult<T>
pub fn dequeue_blocking(&self) -> DequeueResult<T>
Dequeues one task, blocking until work is available or scheduler closes.
Sourcepub fn dequeue_blocking_timeout(&self, timeout: Duration) -> DequeueResult<T>
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.
Sourcepub fn stats(&self) -> SchedulerStats
pub fn stats(&self) -> SchedulerStats
Returns a snapshot of current scheduler metrics.
Sourcepub fn close(&self)
pub fn close(&self)
Alias for Scheduler::close_immediate.
Sourcepub fn close_immediate(&self)
pub fn close_immediate(&self)
Closes immediately: stops accepting new work and wakes blocked consumers.
Sourcepub fn close_drain(&self)
pub fn close_drain(&self)
Closes in drain mode: stops accepting and drains queued work before closing.
Sourcepub fn close_with_mode(&self, mode: CloseMode)
pub fn close_with_mode(&self, mode: CloseMode)
Closes using the provided mode.