Skip to content

Commit a4588f7

Browse files
committed
feat: more progress on sync, added basic README
1 parent 67e565c commit a4588f7

File tree

5 files changed

+241
-29
lines changed

5 files changed

+241
-29
lines changed

Cargo.lock

Lines changed: 109 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aw-sync/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ chrono = { version = "0.4", features = ["serde"] }
1818
serde = "1.0"
1919
serde_json = "1.0"
2020
reqwest = { version = "0.11", features = ["json", "blocking"] }
21+
clap = "3.0.0-beta.2"
2122
aw-server = { path = "../aw-server" }
2223
aw-models = { path = "../aw-models" }
2324
aw-datastore = { path = "../aw-datastore" }

aw-sync/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
aw-sync-rust
2+
============
3+
4+
Synchronization for ActivityWatch.
5+
6+
Works by syncing local buckets with a special folder, which in turn should be synchronized by rsync/Syncthing/Dropbox/whatever.
7+
8+
9+
## Usage
10+
11+
**Note:** this documents usage for testing, it is not yet ready for production usage.
12+
13+
### Pushing to the sync directory
14+
15+
First start your aw-server instance.
16+
17+
For example:
18+
19+
```sh
20+
PORT=5667
21+
cargo run --bin aw-server -- --testing --port $PORT --dbpath test-$PORT.sqlite --device-id $PORT --no-legacy-import
22+
```
23+
24+
You can create some test data by opening `http://localhost:5667/#/stopwatch` and creating a few events.
25+
26+
Then run `cargo run --bin aw-sync-rust` to sync your instance's buckets with the target directory.
27+
28+
### Pulling from the sync directory
29+
30+
Now to sync things back from the sync directory onto another instance. First, lets start another instance:
31+
32+
```
33+
PORT=5668
34+
cargo run --bin aw-server -- --testing --port $PORT --dbpath test-$PORT.sqlite --device-id $PORT --no-legacy-import
35+
```
36+
37+
Now run `aw-sync-rust` again.

aw-sync/src/main.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,23 @@ extern crate serde_json;
66

77
use std::path::Path;
88

9+
use clap::{AppSettings, Clap};
10+
911
use aw_client_rust::AwClient;
1012

1113
mod sync;
1214

15+
#[derive(Clap)]
16+
#[clap(version = "1.0", author = "Erik Bjäreholt")]
17+
#[clap(setting = AppSettings::ColoredHelp)]
18+
struct Opts {
19+
/// Sets a custom config file. Could have been an Option<T> with no default too
20+
#[clap(long, default_value = "127.0.0.1")]
21+
host: String,
22+
#[clap(long, default_value = "5666")]
23+
port: String,
24+
}
25+
1326
fn main() {
1427
// What needs to be done:
1528
// - [x] Setup local sync bucket
@@ -19,13 +32,16 @@ fn main() {
1932
// - [ ] For which local server to use
2033
// - [ ] For which sync dir to use
2134

35+
let opts: Opts = Opts::parse();
36+
2237
println!("Started aw-sync-rust...");
38+
2339
aw_server::logging::setup_logger(true).expect("Failed to setup logging");
2440

2541
// TODO: Get path using dirs module
2642
let sync_directory = Path::new("sync-testing");
2743

28-
let client = AwClient::new("127.0.0.1", "5667", "aw-sync-rust");
44+
let client = AwClient::new(opts.host.as_str(), opts.port.as_str(), "aw-sync-rust");
2945

3046
sync::sync_run(sync_directory, client);
3147
info!("Finished successfully, exiting...");

0 commit comments

Comments
 (0)