Skip to content

Commit

Permalink
fix: minor fixes to sync, renamed sync-testing scripts, improved README
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Aug 30, 2022
1 parent 0c99688 commit 60badc3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
7 changes: 5 additions & 2 deletions aw-sync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cargo run --bin aw-sync-rust -- --port 5666 --help

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:

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

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

4. You should now have all events synced to a local testing instance!
- 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.
- 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.

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").
- 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.

In the end, You should get something like this: https://twitter.com/ErikBjare/status/1519399784234246147


Expand Down
13 changes: 6 additions & 7 deletions aw-sync/src/accessmethod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub trait AccessMethod: std::fmt::Debug {

impl AccessMethod for Datastore {
fn get_buckets(&self) -> Result<HashMap<String, Bucket>, String> {
Ok(self.get_buckets().unwrap())
Ok(Datastore::get_buckets(self).unwrap())
}
fn get_bucket(&self, bucket_id: &str) -> Result<Bucket, DatastoreError> {
Datastore::get_bucket(self, bucket_id)
Expand Down Expand Up @@ -66,10 +66,10 @@ impl AccessMethod for Datastore {

impl AccessMethod for AwClient {
fn get_buckets(&self) -> Result<HashMap<String, Bucket>, String> {
Ok(self.get_buckets().unwrap())
Ok(AwClient::get_buckets(self).unwrap())
}
fn get_bucket(&self, bucket_id: &str) -> Result<Bucket, DatastoreError> {
let bucket = self.get_bucket(bucket_id);
let bucket = AwClient::get_bucket(self, bucket_id);
match bucket {
Ok(bucket) => Ok(bucket),
Err(e) => {
Expand All @@ -90,21 +90,20 @@ impl AccessMethod for AwClient {
end: Option<DateTime<Utc>>,
limit: Option<u64>,
) -> Result<Vec<Event>, String> {
Ok(self.get_events(bucket_id, start, end, limit).unwrap())
Ok(AwClient::get_events(self, bucket_id, start, end, limit).unwrap())
}
fn insert_events(&self, bucket_id: &str, events: Vec<Event>) -> Result<(), String> {
AwClient::insert_events(self, bucket_id, events).map_err(|e| e.to_string())
}
fn get_event_count(&self, bucket_id: &str) -> Result<i64, String> {
Ok(self.get_event_count(bucket_id).unwrap())
Ok(AwClient::get_event_count(self, bucket_id).unwrap())
}
fn create_bucket(&self, bucket: &Bucket) -> Result<(), DatastoreError> {
AwClient::create_bucket(self, bucket).unwrap();
Ok(())
}
fn heartbeat(&self, bucket_id: &str, event: Event, duration: f64) -> Result<(), String> {
self.heartbeat(bucket_id, &event, duration)
.map_err(|e| format!("{:?}", e))
AwClient::heartbeat(self, bucket_id, &event, duration).map_err(|e| format!("{:?}", e))
}
fn close(&self) {
// NOP
Expand Down
2 changes: 2 additions & 0 deletions aw-sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ fn sync_one(

const BATCH_SIZE: usize = 5000;
if BATCH_SIZE == 1 {
// TODO: Don't print progress messages if not in a suitable terminal environment (such as a
// pipe or systemd journal)
for event in events_iter {
print!("{} ({}/{})\r", &event.timestamp, events_sent, events_total);
ds_to.heartbeat(bucket_to.id.as_str(), event, 0.0).unwrap();
Expand Down
6 changes: 4 additions & 2 deletions aw-sync/test-import-sync.sh → aw-sync/test-sync-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if [ "$(lsof -i:$PORT -sTCP:LISTEN -t)" ]; then
else
# Set up an isolated ActivityWatch instance
./test-server.sh $PORT &
SERVER_PID=$!
fi


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

# kill aw-server-rust
#kill %1
fg
if [ "$SERVER_PID" ]; then
kill $SERVER_PID
fi
File renamed without changes.

0 comments on commit 60badc3

Please sign in to comment.