Skip to content

Commit

Permalink
feat: more progress on sync, added basic README
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Jun 8, 2021
1 parent 67e565c commit a4588f7
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 29 deletions.
110 changes: 109 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions aw-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ chrono = { version = "0.4", features = ["serde"] }
serde = "1.0"
serde_json = "1.0"
reqwest = { version = "0.11", features = ["json", "blocking"] }
clap = "3.0.0-beta.2"
aw-server = { path = "../aw-server" }
aw-models = { path = "../aw-models" }
aw-datastore = { path = "../aw-datastore" }
Expand Down
37 changes: 37 additions & 0 deletions aw-sync/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
aw-sync-rust
============

Synchronization for ActivityWatch.

Works by syncing local buckets with a special folder, which in turn should be synchronized by rsync/Syncthing/Dropbox/whatever.


## Usage

**Note:** this documents usage for testing, it is not yet ready for production usage.

### Pushing to the sync directory

First start your aw-server instance.

For example:

```sh
PORT=5667
cargo run --bin aw-server -- --testing --port $PORT --dbpath test-$PORT.sqlite --device-id $PORT --no-legacy-import
```

You can create some test data by opening `http://localhost:5667/#/stopwatch` and creating a few events.

Then run `cargo run --bin aw-sync-rust` to sync your instance's buckets with the target directory.

### Pulling from the sync directory

Now to sync things back from the sync directory onto another instance. First, lets start another instance:

```
PORT=5668
cargo run --bin aw-server -- --testing --port $PORT --dbpath test-$PORT.sqlite --device-id $PORT --no-legacy-import
```

Now run `aw-sync-rust` again.
18 changes: 17 additions & 1 deletion aw-sync/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@ extern crate serde_json;

use std::path::Path;

use clap::{AppSettings, Clap};

use aw_client_rust::AwClient;

mod sync;

#[derive(Clap)]
#[clap(version = "1.0", author = "Erik Bjäreholt")]
#[clap(setting = AppSettings::ColoredHelp)]
struct Opts {
/// Sets a custom config file. Could have been an Option<T> with no default too
#[clap(long, default_value = "127.0.0.1")]
host: String,
#[clap(long, default_value = "5666")]
port: String,
}

fn main() {
// What needs to be done:
// - [x] Setup local sync bucket
Expand All @@ -19,13 +32,16 @@ fn main() {
// - [ ] For which local server to use
// - [ ] For which sync dir to use

let opts: Opts = Opts::parse();

println!("Started aw-sync-rust...");

aw_server::logging::setup_logger(true).expect("Failed to setup logging");

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

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

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

0 comments on commit a4588f7

Please sign in to comment.