feat(http): implement is_indexing for stats

This commit is contained in:
Alexey Shekhirin
2021-04-02 14:44:35 +03:00
parent 09d9a29176
commit 87412f63ef
9 changed files with 65 additions and 22 deletions

View File

@ -72,6 +72,9 @@ where
Some(Snapshot { uuid, path, ret }) => {
let _ = ret.send(self.handle_snapshot(uuid, path).await);
}
Some(IsLocked { uuid, ret }) => {
let _ = ret.send(self.handle_is_locked(uuid).await);
}
None => break,
}
}
@ -223,4 +226,14 @@ where
Ok(())
}
async fn handle_is_locked(&self, uuid: Uuid) -> Result<bool> {
let store = self
.store
.get(uuid)
.await?
.ok_or(UpdateError::UnexistingIndex(uuid))?;
Ok(store.update_lock.is_locked())
}
}

View File

@ -3,11 +3,12 @@ use std::path::{Path, PathBuf};
use tokio::sync::{mpsc, oneshot};
use uuid::Uuid;
use crate::index_controller::IndexActorHandle;
use super::{
MapUpdateStoreStore, PayloadData, Result, UpdateActor, UpdateActorHandle, UpdateMeta,
UpdateMsg, UpdateStatus,
};
use crate::index_controller::IndexActorHandle;
#[derive(Clone)]
pub struct UpdateActorHandleImpl<D> {
@ -36,6 +37,7 @@ where
Ok(Self { sender })
}
}
#[async_trait::async_trait]
impl<D> UpdateActorHandle for UpdateActorHandleImpl<D>
where
@ -43,29 +45,12 @@ where
{
type Data = D;
async fn update(
&self,
meta: UpdateMeta,
data: mpsc::Receiver<PayloadData<Self::Data>>,
uuid: Uuid,
) -> Result<UpdateStatus> {
let (ret, receiver) = oneshot::channel();
let msg = UpdateMsg::Update {
uuid,
data,
meta,
ret,
};
let _ = self.sender.send(msg).await;
receiver.await.expect("update actor killed.")
}
async fn get_all_updates_status(&self, uuid: Uuid) -> Result<Vec<UpdateStatus>> {
let (ret, receiver) = oneshot::channel();
let msg = UpdateMsg::ListUpdates { uuid, ret };
let _ = self.sender.send(msg).await;
receiver.await.expect("update actor killed.")
}
async fn update_status(&self, uuid: Uuid, id: u64) -> Result<UpdateStatus> {
let (ret, receiver) = oneshot::channel();
let msg = UpdateMsg::GetUpdate { uuid, id, ret };
@ -93,4 +78,28 @@ where
let _ = self.sender.send(msg).await;
receiver.await.expect("update actor killed.")
}
async fn update(
&self,
meta: UpdateMeta,
data: mpsc::Receiver<PayloadData<Self::Data>>,
uuid: Uuid,
) -> Result<UpdateStatus> {
let (ret, receiver) = oneshot::channel();
let msg = UpdateMsg::Update {
uuid,
data,
meta,
ret,
};
let _ = self.sender.send(msg).await;
receiver.await.expect("update actor killed.")
}
async fn is_locked(&self, uuid: Uuid) -> Result<bool> {
let (ret, receiver) = oneshot::channel();
let msg = UpdateMsg::IsLocked { uuid, ret };
let _ = self.sender.send(msg).await;
receiver.await.expect("update actor killed.")
}
}

View File

@ -34,4 +34,8 @@ pub enum UpdateMsg<D> {
path: PathBuf,
ret: oneshot::Sender<Result<()>>,
},
IsLocked {
uuid: Uuid,
ret: oneshot::Sender<Result<bool>>,
},
}

View File

@ -52,4 +52,5 @@ pub trait UpdateActorHandle {
data: mpsc::Receiver<PayloadData<Self::Data>>,
uuid: Uuid,
) -> Result<UpdateStatus>;
async fn is_locked(&self, uuid: Uuid) -> Result<bool>;
}