Initial public release

This commit is contained in:
thakares committed 2026-06-11 20:19:03 +05:30
commit c1107147b4
92 files changed
+10562

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
use tokio::sync::mpsc;
use crate::models::VisitRecord;
use crate::db::Db;
#[derive(Clone)]
pub struct AnalyticsQueue {
sender: mpsc::Sender<VisitRecord>,
}
impl AnalyticsQueue {
pub fn new(db: Db, capacity: usize) -> Self {
let (sender, receiver) = mpsc::channel(capacity);
// Spawn background worker to batch-write records
tokio::spawn(async move {
super::worker::run_worker(db, receiver).await;
});
Self { sender }
}
// Attempt to queue a visit. Non-blocking.
pub fn push(&self, record: VisitRecord) {
use tracing::error;
if let Err(e) = self.sender.try_send(record) {
error!("Failed to queue analytics record: {:?}", e);
}
}
}