MeiliSearch/meilisearch-http/src/index_controller/update_actor/mod.rs

52 lines
1.5 KiB
Rust
Raw Normal View History

2021-03-23 11:00:50 +01:00
mod actor;
mod handle_impl;
2021-03-24 11:29:11 +01:00
mod message;
2021-03-23 11:00:50 +01:00
mod update_store;
use std::path::PathBuf;
use thiserror::Error;
use tokio::sync::mpsc;
use uuid::Uuid;
use crate::index::UpdateResult;
use crate::index_controller::{UpdateMeta, UpdateStatus};
use actor::UpdateActor;
use message::UpdateMsg;
pub use handle_impl::UpdateActorHandleImpl;
pub type Result<T> = std::result::Result<T, UpdateError>;
type UpdateStore = update_store::UpdateStore<UpdateMeta, UpdateResult, String>;
type PayloadData<D> = std::result::Result<D, Box<dyn std::error::Error + Sync + Send + 'static>>;
2021-03-23 16:19:01 +01:00
#[cfg(test)]
use mockall::automock;
2021-03-23 11:00:50 +01:00
#[derive(Debug, Error)]
pub enum UpdateError {
#[error("error with update: {0}")]
Error(Box<dyn std::error::Error + Sync + Send + 'static>),
#[error("Update {0} doesn't exist.")]
UnexistingUpdate(u64),
}
#[async_trait::async_trait]
2021-03-23 16:19:01 +01:00
#[cfg_attr(test, automock(type Data=Vec<u8>;))]
2021-03-23 11:00:50 +01:00
pub trait UpdateActorHandle {
type Data: AsRef<[u8]> + Sized + 'static + Sync + Send;
async fn get_all_updates_status(&self, uuid: Uuid) -> Result<Vec<UpdateStatus>>;
async fn update_status(&self, uuid: Uuid, id: u64) -> Result<UpdateStatus>;
async fn delete(&self, uuid: Uuid) -> Result<()>;
2021-04-14 17:53:12 +02:00
async fn snapshot(&self, uuids: Vec<Uuid>, path: PathBuf) -> Result<()>;
async fn get_size(&self) -> Result<u64>;
2021-03-23 11:00:50 +01:00
async fn update(
&self,
meta: UpdateMeta,
data: mpsc::Receiver<PayloadData<Self::Data>>,
uuid: Uuid,
2021-03-24 11:29:11 +01:00
) -> Result<UpdateStatus>;
2021-03-23 11:00:50 +01:00
}