use std::sync::Arc;
use std::time::Duration;
use crate::identity::TaskId;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum SlotStatusKind {
Idle,
Admitting,
Running,
Terminating,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct SlotView {
pub slot: Arc<str>,
pub status: SlotStatusKind,
pub owner_id: Option<TaskId>,
pub queue_depth: usize,
pub status_for: Duration,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct ControllerSnapshot {
pub slots: Vec<SlotView>,
}
impl ControllerSnapshot {
#[must_use]
pub fn running_count(&self) -> usize {
self.slots
.iter()
.filter(|s| s.status == SlotStatusKind::Running)
.count()
}
#[must_use]
pub fn total_queued(&self) -> usize {
self.slots.iter().map(|s| s.queue_depth).sum()
}
#[must_use]
pub fn slot(&self, name: &str) -> Option<&SlotView> {
self.slots.iter().find(|s| &*s.slot == name)
}
#[must_use]
pub fn len(&self) -> usize {
self.slots.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.slots.is_empty()
}
}