2021-05-31 16:03:39 +02:00
|
|
|
use std::path::Path;
|
2021-05-31 16:40:59 +02:00
|
|
|
|
|
|
|
use actix_web::web::Bytes;
|
2021-05-10 20:25:09 +02:00
|
|
|
use tokio::sync::{mpsc, oneshot};
|
|
|
|
|
2021-06-14 21:26:35 +02:00
|
|
|
use super::{DumpActor, DumpActorHandle, DumpInfo, DumpMsg};
|
|
|
|
use super::error::Result;
|
2021-05-31 16:40:59 +02:00
|
|
|
|
2021-05-10 20:25:09 +02:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct DumpActorHandleImpl {
|
|
|
|
sender: mpsc::Sender<DumpMsg>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
|
|
impl DumpActorHandle for DumpActorHandleImpl {
|
2021-06-14 21:26:35 +02:00
|
|
|
async fn create_dump(&self) -> Result<DumpInfo> {
|
2021-05-10 20:25:09 +02:00
|
|
|
let (ret, receiver) = oneshot::channel();
|
|
|
|
let msg = DumpMsg::CreateDump { ret };
|
|
|
|
let _ = self.sender.send(msg).await;
|
|
|
|
receiver.await.expect("IndexActor has been killed")
|
|
|
|
}
|
|
|
|
|
2021-06-14 21:26:35 +02:00
|
|
|
async fn dump_info(&self, uid: String) -> Result<DumpInfo> {
|
2021-05-10 20:25:09 +02:00
|
|
|
let (ret, receiver) = oneshot::channel();
|
|
|
|
let msg = DumpMsg::DumpInfo { ret, uid };
|
|
|
|
let _ = self.sender.send(msg).await;
|
|
|
|
receiver.await.expect("IndexActor has been killed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DumpActorHandleImpl {
|
|
|
|
pub fn new(
|
|
|
|
path: impl AsRef<Path>,
|
|
|
|
uuid_resolver: crate::index_controller::uuid_resolver::UuidResolverHandleImpl,
|
|
|
|
update: crate::index_controller::update_actor::UpdateActorHandleImpl<Bytes>,
|
2021-05-31 16:40:59 +02:00
|
|
|
index_db_size: usize,
|
|
|
|
update_db_size: usize,
|
2021-06-14 21:26:35 +02:00
|
|
|
) -> std::result::Result<Self, Box<dyn std::error::Error>> {
|
2021-05-10 20:25:09 +02:00
|
|
|
let (sender, receiver) = mpsc::channel(10);
|
2021-05-31 16:03:39 +02:00
|
|
|
let actor = DumpActor::new(
|
|
|
|
receiver,
|
|
|
|
uuid_resolver,
|
|
|
|
update,
|
|
|
|
path,
|
|
|
|
index_db_size,
|
|
|
|
update_db_size,
|
|
|
|
);
|
2021-05-10 20:25:09 +02:00
|
|
|
|
|
|
|
tokio::task::spawn(actor.run());
|
2021-05-26 20:42:09 +02:00
|
|
|
|
2021-05-10 20:25:09 +02:00
|
|
|
Ok(Self { sender })
|
|
|
|
}
|
|
|
|
}
|