Collections refactor, unused in ingestor
Ingestor refactor complete baby~ Just make sure everything works fix naming convention
This commit is contained in:
parent
9adc67cf4d
commit
6d60756348
7 changed files with 218 additions and 60 deletions
85
ingestor/src/collections.rs
Normal file
85
ingestor/src/collections.rs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
use rocketman::ingestion::LexiconIngestor;
|
||||
|
||||
macro_rules! create_commit_collection {
|
||||
($collection:ident, $nsid:expr,
|
||||
change => $change_fn:expr,
|
||||
delete => $delete_fn:expr $(,)?
|
||||
) => (
|
||||
create_commit_collection!(
|
||||
$collection, $nsid,
|
||||
create => $change_fn,
|
||||
update => $change_fn,
|
||||
delete => $delete_fn,
|
||||
);
|
||||
);
|
||||
($collection:ident, $nsid:expr,
|
||||
create => $create_fn:expr,
|
||||
update => $update_fn:expr,
|
||||
delete => $delete_fn:expr $(,)?
|
||||
) => (
|
||||
pub struct $collection;
|
||||
struct Ingestor;
|
||||
|
||||
impl $crate::collections::Collection for $collection {
|
||||
fn new() -> Self { Self }
|
||||
|
||||
fn get_nsid(&self) -> String {
|
||||
$nsid
|
||||
}
|
||||
|
||||
fn get_ingestor(
|
||||
&self
|
||||
) -> Box<dyn rocketman::ingestion::LexiconIngestor + Send + Sync> {
|
||||
Box::new(Ingestor::new())
|
||||
}
|
||||
}
|
||||
|
||||
impl Ingestor {
|
||||
pub fn new() -> Self { Self }
|
||||
|
||||
pub async fn handle_commit(
|
||||
&self,
|
||||
message: rocketman::types::event::Event<serde_json::Value>
|
||||
) -> anyhow::Result<()> {
|
||||
use rocketman::types::event::Operation;
|
||||
|
||||
let state = $crate::collections::CommitIngestorState { };
|
||||
|
||||
if let Some(commit) = &message.commit {
|
||||
match commit.operation {
|
||||
Operation::Create => ($create_fn)(state, message).await?,
|
||||
Operation::Update => ($update_fn)(state, message).await?,
|
||||
Operation::Delete => ($delete_fn)(state, message).await?,
|
||||
}
|
||||
} else {
|
||||
return Err(anyhow::anyhow!("Message has no commit"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl rocketman::ingestion::LexiconIngestor for Ingestor {
|
||||
async fn ingest(
|
||||
&self,
|
||||
message: rocketman::types::event::Event<serde_json::Value>
|
||||
) -> anyhow::Result<()> {
|
||||
self.handle_commit(message).await
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
pub mod my_spoor_log_session;
|
||||
pub use my_spoor_log_session::MySpoorLogSession;
|
||||
pub mod my_spoor_log_activity;
|
||||
pub use my_spoor_log_activity::MySpoorLogActivity;
|
||||
|
||||
struct CommitIngestorState;
|
||||
|
||||
pub trait Collection {
|
||||
fn new() -> Self;
|
||||
fn get_nsid(&self) -> String;
|
||||
fn get_ingestor(&self) -> Box<dyn LexiconIngestor + Send + Sync>;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue