@@ -1,14 +1,10 @@
|
||||
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::async_trait;
|
||||
|
||||
use churn_domain::{LogEvent};
|
||||
use churn_domain::LogEvent;
|
||||
use itertools::Itertools;
|
||||
|
||||
|
||||
|
||||
use churn_capnp::CapnpPackExt;
|
||||
|
||||
use crate::db::Db;
|
||||
@@ -52,6 +48,7 @@ pub trait EventServiceTrait {
|
||||
async fn append(&self, req: LogEvent) -> anyhow::Result<()>;
|
||||
async fn get_from_cursor(&self, cursor: uuid::Uuid) -> anyhow::Result<Vec<LogEvent>>;
|
||||
async fn get_from_beginning(&self) -> anyhow::Result<Vec<LogEvent>>;
|
||||
async fn get_latest_cursor(&self) -> anyhow::Result<uuid::Uuid>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -93,4 +90,25 @@ impl EventServiceTrait for DefaultEventService {
|
||||
|
||||
Ok(events)
|
||||
}
|
||||
|
||||
async fn get_latest_cursor(&self) -> anyhow::Result<uuid::Uuid> {
|
||||
let events = self.db.get_all("events_log").await?;
|
||||
|
||||
let event = events
|
||||
.iter()
|
||||
.flat_map(|e| match LogEvent::deserialize_capnp(e) {
|
||||
Ok(o) => Ok(o),
|
||||
Err(e) => {
|
||||
tracing::error!("failed to deserialize capnp: {e}");
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
.sorted_by_key(|i| i.timestamp)
|
||||
.last();
|
||||
|
||||
match event {
|
||||
Some(x) => Ok(x.id),
|
||||
None => anyhow::bail!("no events found"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user