use std::path::PathBuf; use tokio::sync::{mpsc, oneshot}; use uuid::Uuid; use crate::index::Index; use super::error::Result; use super::{Update, UpdateStatus, UpdateStoreInfo}; #[derive(Debug)] pub enum UpdateMsg { Update { uuid: Uuid, update: Update, ret: oneshot::Sender>, }, ListUpdates { uuid: Uuid, ret: oneshot::Sender>>, }, GetUpdate { uuid: Uuid, ret: oneshot::Sender>, id: u64, }, DeleteIndex { uuid: Uuid, ret: oneshot::Sender>, }, Snapshot { indexes: Vec, path: PathBuf, ret: oneshot::Sender>, }, Dump { indexes: Vec, path: PathBuf, ret: oneshot::Sender>, }, GetInfo { ret: oneshot::Sender>, }, } impl UpdateMsg { pub async fn snapshot( sender: &mpsc::Sender, path: PathBuf, indexes: Vec, ) -> Result<()> { let (ret, rcv) = oneshot::channel(); let msg = Self::Snapshot { path, indexes, ret }; sender.send(msg).await?; rcv.await? } pub async fn dump( sender: &mpsc::Sender, indexes: Vec, path: PathBuf, ) -> Result<()> { let (ret, rcv) = oneshot::channel(); let msg = Self::Dump { path, indexes, ret }; sender.send(msg).await?; rcv.await? } pub async fn update( sender: &mpsc::Sender, uuid: Uuid, update: Update, ) -> Result { let (ret, rcv) = oneshot::channel(); let msg = Self::Update { uuid, update, ret }; sender.send(msg).await?; rcv.await? } pub async fn get_update( sender: &mpsc::Sender, uuid: Uuid, id: u64, ) -> Result { let (ret, rcv) = oneshot::channel(); let msg = Self::GetUpdate { uuid, id, ret }; sender.send(msg).await?; rcv.await? } pub async fn list_updates( sender: &mpsc::Sender, uuid: Uuid, ) -> Result> { let (ret, rcv) = oneshot::channel(); let msg = Self::ListUpdates { uuid, ret }; sender.send(msg).await?; rcv.await? } pub async fn get_info(sender: &mpsc::Sender) -> Result { let (ret, rcv) = oneshot::channel(); let msg = Self::GetInfo { ret }; sender.send(msg).await?; rcv.await? } pub async fn delete(sender: &mpsc::Sender, uuid: Uuid) -> Result<()> { let (ret, rcv) = oneshot::channel(); let msg = Self::DeleteIndex { ret, uuid }; sender.send(msg).await?; rcv.await? } }