use anyhow::Result;
use surreal_sync_core::{CheckpointStore, InterleavedSnapshotCheckpoint, SyncManager, SyncPhase};
pub use surreal_sync_core::SnapshotCheckpointer;
#[derive(Debug, Default, Clone, Copy)]
pub struct NoopCheckpointer;
#[async_trait::async_trait]
impl SnapshotCheckpointer for NoopCheckpointer {
async fn save_progress(&mut self, _checkpoint: &InterleavedSnapshotCheckpoint) -> Result<()> {
Ok(())
}
}
pub struct ManagerCheckpointer<S: CheckpointStore> {
manager: SyncManager<S>,
}
impl<S: CheckpointStore> ManagerCheckpointer<S> {
pub fn new(manager: SyncManager<S>) -> Self {
Self { manager }
}
pub async fn save_handoff(&self, checkpoint: &InterleavedSnapshotCheckpoint) -> Result<()> {
self.manager
.emit_checkpoint(checkpoint, SyncPhase::SnapshotHandoff)
.await
}
pub fn manager(&self) -> &SyncManager<S> {
&self.manager
}
}
#[async_trait::async_trait]
impl<S: CheckpointStore> SnapshotCheckpointer for ManagerCheckpointer<S> {
async fn save_progress(&mut self, checkpoint: &InterleavedSnapshotCheckpoint) -> Result<()> {
self.manager
.emit_checkpoint(checkpoint, SyncPhase::SnapshotProgress)
.await
}
}