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;
|
|
|
|
|
2021-04-22 10:14:29 +02:00
|
|
|
use std::{collections::HashSet, path::PathBuf};
|
2021-03-23 11:00:50 +01:00
|
|
|
|
2021-05-25 09:46:11 +02:00
|
|
|
use actix_http::error::PayloadError;
|
2021-03-23 11:00:50 +01:00
|
|
|
use thiserror::Error;
|
|
|
|
use tokio::sync::mpsc;
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
use crate::index_controller::{UpdateMeta, UpdateStatus};
|
|
|
|
|
|
|
|
use actor::UpdateActor;
|
|
|
|
use message::UpdateMsg;
|
|
|
|
|
|
|
|
pub use handle_impl::UpdateActorHandleImpl;
|
2021-05-25 09:46:11 +02:00
|
|
|
pub use update_store::{UpdateStore, UpdateStoreInfo};
|
2021-03-23 11:00:50 +01:00
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, UpdateError>;
|
2021-05-25 09:46:11 +02:00
|
|
|
type PayloadData<D> = std::result::Result<D, PayloadError>;
|
2021-03-23 11:00:50 +01:00
|
|
|
|
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("Update {0} doesn't exist.")]
|
|
|
|
UnexistingUpdate(u64),
|
2021-05-25 09:46:11 +02:00
|
|
|
#[error("Internal error processing update: {0}")]
|
|
|
|
Internal(String),
|
2021-03-23 11:00:50 +01:00
|
|
|
}
|
|
|
|
|
2021-05-25 09:46:11 +02:00
|
|
|
macro_rules! internal_error {
|
|
|
|
($($other:path), *) => {
|
|
|
|
$(
|
|
|
|
impl From<$other> for UpdateError {
|
|
|
|
fn from(other: $other) -> Self {
|
|
|
|
Self::Internal(other.to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal_error!(
|
|
|
|
heed::Error,
|
|
|
|
std::io::Error,
|
|
|
|
serde_json::Error,
|
|
|
|
PayloadError,
|
|
|
|
tokio::task::JoinError,
|
|
|
|
anyhow::Error
|
|
|
|
);
|
|
|
|
|
2021-03-23 11:00:50 +01:00
|
|
|
#[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-05-10 20:24:14 +02:00
|
|
|
async fn snapshot(&self, uuid: HashSet<Uuid>, path: PathBuf) -> Result<()>;
|
2021-05-05 14:11:56 +02:00
|
|
|
async fn dump(&self, uuid: HashSet<(String, Uuid)>, path: PathBuf) -> Result<()>;
|
2021-04-14 18:55:04 +02:00
|
|
|
async fn get_info(&self) -> Result<UpdateStoreInfo>;
|
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
|
|
|
}
|