aw-sync: add --mode to daemon, fix unrespected --start-date#620
aw-sync: add --mode to daemon, fix unrespected --start-date#6200xbrayo wants to merge 3 commits into
Conversation
The daemon previously hardcoded SyncMode::Both, requiring users to run "aw-sync sync" in a loop to get push-only or pull-only behavior. Adds the same --mode push|pull|both flag already available on the sync subcommand. Closes ActivityWatch#485
SyncSpec.start was parsed from the CLI but never read by sync_one, so --start-date had no effect. Now used as the resume point when a destination bucket has no events yet (first sync), falling back to the last-synced event's end time on subsequent runs as before.
Greptile SummaryThis PR adds a
Confidence Score: 4/5Safe to merge; the daemon now respects --mode and --start-date is correctly applied only to empty destination buckets. Both changes are small and well-scoped. The --mode wiring is a direct pass-through with no new logic. The --start-date fix is correct: sync_spec.start is used as a fallback only when the destination bucket has no events, so repeat daemon iterations naturally skip it once events exist. No data loss or duplicate-event scenarios are introduced. aw-sync/src/sync.rs — verify the get_events ordering assumption (limit=1 returns most-recent) holds for all AccessMethod implementations, since sync_one relies on it for the resume point. Important Files Changed
Sequence DiagramsequenceDiagram
participant CLI
participant DaemonFn as daemon()
participant SyncRun as sync_run()
participant SyncDS as sync_datastores()
participant SyncOne as sync_one()
CLI->>DaemonFn: "--mode push|pull|both, --start-date"
loop every 5 minutes
DaemonFn->>SyncRun: sync_spec, mode
alt mode is Pull or Both
SyncRun->>SyncDS: ds_remote to ds_local
SyncDS->>SyncOne: bucket_from, bucket_to, sync_spec
SyncOne->>SyncOne: get_events dest limit 1
alt destination has events
SyncOne->>SyncOne: resume from last event end time
else destination is empty
SyncOne->>SyncOne: resume from sync_spec.start
end
SyncOne->>SyncOne: fetch and insert events
end
alt mode is Push or Both
SyncRun->>SyncDS: ds_local to ds_sync_folder
SyncDS->>SyncOne: bucket_from, bucket_to, sync_spec
end
SyncRun-->>DaemonFn: Ok
end
|
Previously, "aw-sync sync --mode push" with no other flags fell through to the legacy host-based sync path, which always does both a pull and a push regardless of --mode. Make mode an Option so an explicit --mode opts into the advanced sync path (where it's respected), matching the documented behavior.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #620 +/- ##
==========================================
+ Coverage 70.81% 77.09% +6.28%
==========================================
Files 51 62 +11
Lines 2916 4956 +2040
==========================================
+ Hits 2065 3821 +1756
- Misses 851 1135 +284 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
--mode push|pull|bothtoaw-sync daemon(previously hardcoded toBoth), matching the option already available onaw-sync sync. Closes Add more options to aw-sync daemon #485.--start-date, which was parsed intoSyncSpec.startbut never read. It's now used as the resume point on the first sync of a bucket (when the destination has no events yet), with subsequent runs resuming from the last-synced event as before.Test plan
cargo build -p aw-sync --features clicargo test -p aw-sync --features cli(3 passed)cargo clippy -p aw-sync --features cli(no new warnings)aw-sync daemon --helpshows the new--modeflag