diff options
author | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-03-07 14:19:26 +0000 |
---|---|---|
committer | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-03-11 16:47:56 +0000 |
commit | bd80ac0e918ff923dbb3fc1a6d89fa56a313683b (patch) | |
tree | 1c04e3e312742248892ea4a77940209a9b00e2a0 | |
parent | 773b7e8850af838fe3d4734763af7d8058f4b453 (diff) |
add sync workerellie/daemon
-rw-r--r-- | atuin-daemon/src/server/sync.rs | 31 |
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" + ); + } +} |