From 13f510c1dc9e91712855059b736a060a0a493f0d Mon Sep 17 00:00:00 2001 From: yse Date: Mon, 18 Nov 2024 03:04:19 +0100 Subject: [PATCH] feat: add `run` method --- 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 498d84150..016886731 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,