mod metrics;
mod protocol;
use crate::common::protocols::DirectRequest;
use tokio::sync::{mpsc, oneshot};
use uuid::Uuid;
pub use crate::common::protocols::ForwardPassSnapshot;
pub use metrics::MockerMetrics;
pub use protocol::{
SchedulerCommand, SchedulerCommandEffects, SchedulerCommandResult, SchedulerLifecycleEvent,
};
#[derive(Debug, Clone)]
pub(crate) struct AdmissionEvent {
pub(crate) uuid: Uuid,
pub(crate) reused_input_tokens: usize,
}
pub struct SchedulerCommandEnvelope {
pub command: SchedulerCommand,
pub reply: oneshot::Sender<anyhow::Result<SchedulerCommandEffects>>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum RouterEventVisibility {
PassStart,
PassEnd,
}
pub struct SchedulerCancellationEnvelope {
pub request_id: Uuid,
pub discard_pending_output: bool,
pub reply: oneshot::Sender<anyhow::Result<SchedulerCommandEffects>>,
}
impl From<SchedulerCancellationEnvelope> for SchedulerCommandEnvelope {
fn from(cancellation: SchedulerCancellationEnvelope) -> Self {
Self {
command: SchedulerCommand::CancelRequest {
request_id: cancellation.request_id,
},
reply: cancellation.reply,
}
}
}
pub trait SchedulerHandle: Send + Sync {
fn receive(&self, request: DirectRequest);
fn request_sender(&self) -> mpsc::UnboundedSender<DirectRequest>;
fn metrics_receiver(&self) -> tokio::sync::watch::Receiver<MockerMetrics>;
fn command_sender(&self) -> mpsc::Sender<SchedulerCommandEnvelope>;
fn cancellation_sender(&self) -> mpsc::Sender<SchedulerCancellationEnvelope>;
fn take_lifecycle_receiver(&mut self) -> Option<mpsc::Receiver<SchedulerLifecycleEvent>>;
}
pub(crate) fn handoff_channel_capacity(args: &crate::common::protocols::MockerConfig) -> usize {
args.effective_handoff_capacity()
.checked_mul(2)
.expect("mocker handoff channel capacity overflow")
}