Skip to content

Commit

Permalink
fix: windows and aw-server-rust issues
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierMary committed Feb 4, 2023
1 parent 1f86654 commit 7baf52b
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 20 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'fr.mary.olivier'
version '2.0.3'
version '2.0.4'

repositories {
mavenCentral()
Expand Down Expand Up @@ -83,6 +83,10 @@ intellij {
}
patchPluginXml {
setChangeNotes """
2.0.4<br>
- Fix aw-server-rust schema differences<br>
- Fix very slow aw-server issues (windows)<br>
- Use async http client<br>
2.0.3<br>
- Fix unknown editor name in final version<br>
2.0.2<br>
Expand Down
132 changes: 114 additions & 18 deletions src/main/java/fr/mary/olivier/aw/watcher/ReportActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import fr.mary.olivier.aw.watcher.listener.RAVisibleAreaListener;
import git4idea.GitUtil;
import git4idea.repo.GitRepositoryManager;
import org.openapitools.client.ApiCallback;
import org.openapitools.client.ApiException;
import org.openapitools.client.api.DefaultApi;
import org.openapitools.client.model.Bucket;
import org.openapitools.client.model.CreateBucket;
Expand All @@ -29,6 +31,8 @@
import java.awt.*;
import java.net.InetAddress;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
Expand All @@ -46,6 +50,8 @@ public class ReportActivity implements Disposable {
public static final int HEARTBEAT_PULSETIME = 20;
public static final int CHECK_CONNEXION_DELAY = 10;
private static final DefaultApi API_CLIENT = new DefaultApi();
public static final int CONNECTION_TIMEOUT = 200000;
public static final int READ_WRITE_TIMEOUT = 100000;
private static Bucket bucket;
private static final ScheduledExecutorService connexionScheduler = Executors.newScheduledThreadPool(1);
private static ScheduledFuture<?> scheduledConnexion;
Expand Down Expand Up @@ -117,7 +123,28 @@ public static void sendHeartBeat(VirtualFile file, Project project) {
Event event = new Event().data(data).timestamp(OffsetDateTime.now());

try {
API_CLIENT.postHeartbeatResource(bucket.getId(), event, "" + (HEARTBEAT_PULSETIME));
API_CLIENT.postHeartbeatResourceAsync(bucket.getId(), event, "" + HEARTBEAT_PULSETIME, new ApiCallback<>() {
@Override
public void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
LOG.error("Unable to send heartbeat", e);
ReportActivity.connexionLost();
}

@Override
public void onSuccess(Void result, int statusCode, Map<String, List<String>> responseHeaders) {

}

@Override
public void onUploadProgress(long bytesWritten, long contentLength, boolean done) {

}

@Override
public void onDownloadProgress(long bytesRead, long contentLength, boolean done) {

}
});
} catch (Exception e) {
LOG.error("Unable to send heartbeat", e);
ReportActivity.connexionLost();
Expand All @@ -136,28 +163,97 @@ private static void initBucket() {
}

try {
bucket = API_CLIENT.getBucketResource(bucketClientNamePrefix + "_" + hostname);
String finalHostname = hostname;
API_CLIENT.getBucketResourceAsync(bucketClientNamePrefix + "_" + hostname, new ApiCallback<>() {

@Override
public void onSuccess(Bucket result, int statusCode, Map<String, List<String>> responseHeaders) {
LOG.info("Bucket found");
bucket = result;
}

@Override
public void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
LOG.info("Bucket not found, create it");
CreateBucket nb = new CreateBucket();
nb.setClient(bucketClientNamePrefix);
nb.setHostname(finalHostname);
nb.setType(TYPE);
try {
API_CLIENT.postBucketResourceAsync(bucketClientNamePrefix + "_" + finalHostname, nb, new ApiCallback<>() {

@Override
public void onSuccess(Void result, int statusCode, Map<String, List<String>> responseHeaders) {
LOG.info("Bucket created");
try {
API_CLIENT.getBucketResourceAsync(bucketClientNamePrefix + "_" + finalHostname, new ApiCallback<>() {
@Override
public void onSuccess(Bucket result, int statusCode, Map<String, List<String>> responseHeaders) {
LOG.info("Bucket found");
bucket = result;
}

@Override
public void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
LOG.error("Unable to init bucket", e);
connexionLost = true;
}


@Override
public void onUploadProgress(long bytesWritten, long contentLength, boolean done) {
}

@Override
public void onDownloadProgress(long bytesRead, long contentLength, boolean done) {
}
});
} catch (ApiException ex) {
LOG.error("Unable to init bucket", ex);
}
}

@Override
public void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
LOG.error("Unable to create bucket", e);
}

@Override
public void onUploadProgress(long bytesWritten, long contentLength, boolean done) {

}

@Override
public void onDownloadProgress(long bytesRead, long contentLength, boolean done) {

}
}

);
} catch (Exception expB) {
LOG.error("Unable to create bucket", expB);
}
}


@Override
public void onUploadProgress(long bytesWritten, long contentLength, boolean done) {
}

@Override
public void onDownloadProgress(long bytesRead, long contentLength, boolean done) {
}
});
} catch (Exception exp) {
CreateBucket nb = new CreateBucket();
nb.setClient(bucketClientNamePrefix);
try {
nb.setHostname(InetAddress.getLocalHost().getHostName());
} catch (Exception e1) {
nb.setHostname("unknown");
}
nb.setType(TYPE);
try {
API_CLIENT.postBucketResource(bucketClientNamePrefix + "_" + hostname, nb);
bucket = API_CLIENT.getBucketResource(bucketClientNamePrefix + "_" + hostname);
} catch (Exception expBis) {
LOG.warn("Unable to init bucket", expBis);
connexionLost = true;
}
LOG.error("Unable to init bucket", exp);
connexionLost = true;
}
}

private static void setupConnexionToApi() {

API_CLIENT.getApiClient().setConnectTimeout(CONNECTION_TIMEOUT);
API_CLIENT.getApiClient().setReadTimeout(READ_WRITE_TIMEOUT);
API_CLIENT.getApiClient().setWriteTimeout(READ_WRITE_TIMEOUT);
final Runnable handler = () -> {
if (bucket == null) {
initBucket();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<id>fr.mary.olivier.aw-watcher</id>
<name>Activity Watcher</name>
<vendor email="[email protected]" url="https://github.com/OlivierMary">OlivierMARY</vendor>
<version>2.0.3</version>
<version>2.0.4</version>

<description><![CDATA[
This extension allows the open source tracking tool ActivityWatch to keep track of the projects and coding languages you use in jetbrains IDEs.
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,13 @@ definitions:
data:
description: ''
type: object
metadata:
description: ''
type: object
last_updated:
description: The last updated datetime of the bucket
type: string
format: date-time
events:
type: array
items:
Expand Down

0 comments on commit 7baf52b

Please sign in to comment.