From ae6e68e681b34486987eaa41f785cdccd97ce802 Mon Sep 17 00:00:00 2001 From: yse Date: Sat, 16 Nov 2024 01:57:01 +0100 Subject: [PATCH] feat: add `run` --- lib/core/src/sync/mod.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/core/src/sync/mod.rs b/lib/core/src/sync/mod.rs index 9fc5e192e..abcdf85d7 100644 --- a/lib/core/src/sync/mod.rs +++ b/lib/core/src/sync/mod.rs @@ -1,7 +1,9 @@ use std::collections::HashMap; use std::sync::Arc; +use std::time::Duration; use anyhow::{anyhow, Result}; +use futures_util::TryFutureExt; use crate::sync::model::sync::{Record, SetRecordRequest, SetRecordStatus}; use crate::utils; @@ -52,6 +54,21 @@ impl SyncService { } } + async fn run(self: Arc) -> Result<()> { + let cloned = self.clone(); + + tokio::spawn(async move { + loop { + if let Err(err) = cloned.pull().and_then(|_| cloned.push()).await { + log::debug!("Could not run sync event loop: {err:?}"); + } + tokio::time::sleep(Duration::from_secs(30)).await; + } + }); + + Ok(()) + } + fn commit_record( &self, decrypted_record: &DecryptedRecord,