summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2024-03-07 14:19:26 +0000
committerEllie Huxtable <ellie@elliehuxtable.com>2024-03-11 16:47:56 +0000
commitbd80ac0e918ff923dbb3fc1a6d89fa56a313683b (patch)
tree1c04e3e312742248892ea4a77940209a9b00e2a0
parent773b7e8850af838fe3d4734763af7d8058f4b453 (diff)
add sync workerellie/daemon
-rw-r--r--atuin-daemon/src/server/sync.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/atuin-daemon/src/server/sync.rs b/atuin-daemon/src/server/sync.rs
new file mode 100644
index 00000000..363e20eb
--- /dev/null
+++ b/atuin-daemon/src/server/sync.rs
@@ -0,0 +1,31 @@
+use eyre::{Result, WrapErr};
+use tokio::time::{self, MissedTickBehavior};
+
+use atuin_client::{
+ encryption,
+ history::store::HistoryStore,
+ record::{sqlite_store::SqliteStore, sync},
+ settings::Settings,
+};
+
+pub async fn worker(settings: Settings, store: SqliteStore) -> Result<()> {
+ tracing::info!("booting sync worker");
+ let mut ticker = time::interval(time::Duration::from_secs(5));
+
+ // IMPORTANT: without this, if we miss ticks because a sync takes ages or is otherwise delayed,
+ // we may end up running a lot of syncs in a hot loop. No bueno!
+ ticker.set_missed_tick_behavior(MissedTickBehavior::Skip);
+
+ loop {
+ ticker.tick().await;
+ tracing::info!("sync worker tick");
+
+ let (uploaded, downloaded) = sync::sync(&settings, &store).await?;
+
+ tracing::info!(
+ uploaded = ?uploaded,
+ downloaded = ?downloaded,
+ "sync complete"
+ );
+ }
+}