use std::sync::Arc;
use tokio::sync::oneshot;
use super::completion::{OutcomeTx, RemovalCompletion};
use crate::{error::RuntimeError, identity::TaskId, tasks::TaskSpec};
pub(crate) type AddReply = Result<(), RuntimeError>;
pub(crate) type AddReplyRx = oneshot::Receiver<AddReply>;
pub(crate) struct AddBatchItem {
pub(crate) id: TaskId,
pub(crate) label: Arc<str>,
pub(crate) spec: TaskSpec,
}
pub(crate) type RemoveReply = Result<bool, RuntimeError>;
pub(crate) type RemoveReplyRx = oneshot::Receiver<RemoveReply>;
pub(crate) struct CancelDecision {
pub(crate) id: TaskId,
pub(crate) claimed: bool,
pub(super) completion: RemovalCompletion,
}
impl CancelDecision {
pub(crate) async fn wait(&self) {
self.completion.wait().await;
}
pub(crate) fn is_complete(&self) -> bool {
self.completion.is_complete()
}
}
pub(crate) type CancelReply = Result<Option<CancelDecision>, RuntimeError>;
pub(crate) type CancelReplyRx = oneshot::Receiver<CancelReply>;
pub(crate) enum RegistryCommand {
Add {
id: TaskId,
spec: TaskSpec,
outcome: Option<OutcomeTx>,
completion: Option<RemovalCompletion>,
reply: oneshot::Sender<AddReply>,
},
AddBatch {
items: Vec<AddBatchItem>,
reply: oneshot::Sender<AddReply>,
},
Remove {
id: TaskId,
reply: oneshot::Sender<RemoveReply>,
},
RemoveByLabel {
label: Arc<str>,
reply: oneshot::Sender<RemoveReply>,
},
Cancel {
id: TaskId,
reply: oneshot::Sender<CancelReply>,
},
CancelByLabel {
label: Arc<str>,
reply: oneshot::Sender<CancelReply>,
},
}
pub(super) enum RegistryControl {
Fence { reply: oneshot::Sender<()> },
}