implement get single udpate

This commit is contained in:
mpostma 2021-03-06 10:51:52 +01:00
parent a9c7b73744
commit 7d28f8cff0
No known key found for this signature in database
GPG key ID: CBC8A7C1D7A28C3A
6 changed files with 38 additions and 8 deletions

View file

@ -59,10 +59,8 @@ impl Data {
//Ok(())
}
#[inline]
pub fn get_update_status(&self, index: impl AsRef<str>, uid: u64) -> anyhow::Result<Option<UpdateStatus>> {
todo!()
//self.index_controller.update_status(index, uid)
pub async fn get_update_status(&self, index: impl AsRef<str>, uid: u64) -> anyhow::Result<Option<UpdateStatus>> {
self.index_controller.update_status(index.as_ref().to_string(), uid).await
}
pub async fn get_updates_status(&self, index: impl AsRef<str>) -> anyhow::Result<Vec<UpdateStatus>> {

View file

@ -150,8 +150,13 @@ impl IndexController {
todo!()
}
fn update_status(&self, index: String, id: u64) -> anyhow::Result<Option<UpdateStatus>> {
todo!()
pub async fn update_status(&self, index: String, id: u64) -> anyhow::Result<Option<UpdateStatus>> {
let uuid = self.uuid_resolver
.resolve(index)
.await?
.context("index not found")?;
let result = self.update_handle.update_status(uuid, id).await?;
Ok(result)
}
pub async fn all_update_status(&self, index: String) -> anyhow::Result<Vec<UpdateStatus>> {

View file

@ -38,6 +38,11 @@ enum UpdateMsg<D> {
uuid: Uuid,
ret: oneshot::Sender<Result<Vec<UpdateStatus>>>,
},
GetUpdate {
uuid: Uuid,
ret: oneshot::Sender<Result<Option<UpdateStatus>>>,
id: u64,
}
}
struct UpdateActor<D, S> {
@ -81,6 +86,9 @@ where
Some(ListUpdates { uuid, ret }) => {
let _ = ret.send(self.handle_list_updates(uuid).await);
} ,
Some(GetUpdate { uuid, ret, id }) => {
let _ = ret.send(self.handle_get_update(uuid, id).await);
}
None => {}
}
}
@ -154,6 +162,17 @@ where
}).await
.map_err(|e| UpdateError::Error(Box::new(e)))?
}
async fn handle_get_update(&self, uuid: Uuid, id: u64) -> Result<Option<UpdateStatus>> {
let store = self.store
.get(&uuid)
.await?
.ok_or(UpdateError::UnexistingIndex(uuid))?;
let result = store.meta(id)
.map_err(|e| UpdateError::Error(Box::new(e)))?;
Ok(result)
}
}
#[derive(Clone)]
@ -199,6 +218,13 @@ where
let _ = self.sender.send(msg).await;
receiver.await.expect("update actor killed.")
}
pub async fn update_status(&self, uuid: Uuid, id: u64) -> Result<Option<UpdateStatus>> {
let (ret, receiver) = oneshot::channel();
let msg = UpdateMsg::GetUpdate { uuid, id, ret };
let _ = self.sender.send(msg).await;
receiver.await.expect("update actor killed.")
}
}
struct MapUpdateStoreStore {

View file

@ -133,7 +133,7 @@ async fn get_update_status(
data: web::Data<Data>,
path: web::Path<UpdateParam>,
) -> Result<HttpResponse, ResponseError> {
let result = data.get_update_status(&path.index_uid, path.update_id);
let result = data.get_update_status(&path.index_uid, path.update_id).await;
match result {
Ok(Some(meta)) => {
let json = serde_json::to_string(&meta).unwrap();