Skip to content

Commit 60badc3

Browse files
committed
fix: minor fixes to sync, renamed sync-testing scripts, improved README
1 parent 0c99688 commit 60badc3

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

aw-sync/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cargo run --bin aw-sync-rust -- --port 5666 --help
1818

1919
To test syncing real events to a sync folder which can then be pulled from, we will use some helper scripts to do the following:
2020

21-
1. `./test-sync.sh`
21+
1. `./test-sync-push.sh`
2222
- Creates a sync directory **for you to set up sync** with Syncthing/Dropbox/Gdrive/rclone/whatever
2323
- By default `~/ActivityWatchSync`
2424
- Creates a datastore for the current host in the sync folder
@@ -27,13 +27,16 @@ To test syncing real events to a sync folder which can then be pulled from, we w
2727
2. `./test-server.sh`
2828
- Starts a testing server **on port 5667** using a temporary directory as datastore (`/tmp/...`)
2929

30-
3. `./test-import-sync.sh`
30+
3. `./test-sync-pull.sh`
3131
- Imports all the events from sync folder into the testing server on port 5667
3232

3333
4. You should now have all events synced to a local testing instance!
3434
- You can browse [127.0.0.1:5667](http://127.0.0.1:5667) to view testing instance, where you'll see events from synced all hosts.
3535
- You can now set up syncing for `~/ActivityWatchSync` on more devices, and on each one use the script `./test-sync.sh` to push their events into the sync folder, then run `./test-import-sync.sh` on the device where you have the testing instance to update the data there.
3636

37+
5. To view data from all devices at once, go into [127.0.0.1:5667/#/settings](127.0.0.1:5667/#/settings) and check the "Use multidevice query" checkbox (near the bottom, under "developer settings").
38+
- You can now navigate back to the activity view for any device, where you should see data from multiple devices being included in (most of) the visualizations.
39+
3740
In the end, You should get something like this: https://twitter.com/ErikBjare/status/1519399784234246147
3841

3942

aw-sync/src/accessmethod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub trait AccessMethod: std::fmt::Debug {
2727

2828
impl AccessMethod for Datastore {
2929
fn get_buckets(&self) -> Result<HashMap<String, Bucket>, String> {
30-
Ok(self.get_buckets().unwrap())
30+
Ok(Datastore::get_buckets(self).unwrap())
3131
}
3232
fn get_bucket(&self, bucket_id: &str) -> Result<Bucket, DatastoreError> {
3333
Datastore::get_bucket(self, bucket_id)
@@ -66,10 +66,10 @@ impl AccessMethod for Datastore {
6666

6767
impl AccessMethod for AwClient {
6868
fn get_buckets(&self) -> Result<HashMap<String, Bucket>, String> {
69-
Ok(self.get_buckets().unwrap())
69+
Ok(AwClient::get_buckets(self).unwrap())
7070
}
7171
fn get_bucket(&self, bucket_id: &str) -> Result<Bucket, DatastoreError> {
72-
let bucket = self.get_bucket(bucket_id);
72+
let bucket = AwClient::get_bucket(self, bucket_id);
7373
match bucket {
7474
Ok(bucket) => Ok(bucket),
7575
Err(e) => {
@@ -90,21 +90,20 @@ impl AccessMethod for AwClient {
9090
end: Option<DateTime<Utc>>,
9191
limit: Option<u64>,
9292
) -> Result<Vec<Event>, String> {
93-
Ok(self.get_events(bucket_id, start, end, limit).unwrap())
93+
Ok(AwClient::get_events(self, bucket_id, start, end, limit).unwrap())
9494
}
9595
fn insert_events(&self, bucket_id: &str, events: Vec<Event>) -> Result<(), String> {
9696
AwClient::insert_events(self, bucket_id, events).map_err(|e| e.to_string())
9797
}
9898
fn get_event_count(&self, bucket_id: &str) -> Result<i64, String> {
99-
Ok(self.get_event_count(bucket_id).unwrap())
99+
Ok(AwClient::get_event_count(self, bucket_id).unwrap())
100100
}
101101
fn create_bucket(&self, bucket: &Bucket) -> Result<(), DatastoreError> {
102102
AwClient::create_bucket(self, bucket).unwrap();
103103
Ok(())
104104
}
105105
fn heartbeat(&self, bucket_id: &str, event: Event, duration: f64) -> Result<(), String> {
106-
self.heartbeat(bucket_id, &event, duration)
107-
.map_err(|e| format!("{:?}", e))
106+
AwClient::heartbeat(self, bucket_id, &event, duration).map_err(|e| format!("{:?}", e))
108107
}
109108
fn close(&self) {
110109
// NOP

aw-sync/src/sync.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ fn sync_one(
349349

350350
const BATCH_SIZE: usize = 5000;
351351
if BATCH_SIZE == 1 {
352+
// TODO: Don't print progress messages if not in a suitable terminal environment (such as a
353+
// pipe or systemd journal)
352354
for event in events_iter {
353355
print!("{} ({}/{})\r", &event.timestamp, events_sent, events_total);
354356
ds_to.heartbeat(bucket_to.id.as_str(), event, 0.0).unwrap();

aw-sync/test-import-sync.sh renamed to aw-sync/test-sync-pull.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ if [ "$(lsof -i:$PORT -sTCP:LISTEN -t)" ]; then
1313
else
1414
# Set up an isolated ActivityWatch instance
1515
./test-server.sh $PORT &
16+
SERVER_PID=$!
1617
fi
1718

1819

@@ -32,5 +33,6 @@ for host in $(ls $SYNCROOTDIR); do
3233
done
3334

3435
# kill aw-server-rust
35-
#kill %1
36-
fg
36+
if [ "$SERVER_PID" ]; then
37+
kill $SERVER_PID
38+
fi
File renamed without changes.

0 commit comments

Comments
 (0)