Skip to content

Commit

Permalink
Complete python gRPC requests when closing
Browse files Browse the repository at this point in the history
  • Loading branch information
cbornet committed Nov 6, 2023
1 parent 6ca69e9 commit 230c202
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void stopChannel(boolean wait) throws Exception {

@Override
public synchronized void close() throws Exception {
stopBeforeRestart();
stopChannel(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ public void process(List<ai.langstream.api.runner.code.Record> records, RecordSi
}
}

@Override
public synchronized void close() throws Exception {
stopBeforeRestart();
}

private SourceRecordAndResult fromGrpc(
ai.langstream.api.runner.code.Record sourceRecord, ProcessorResult result)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ protected void stopBeforeRestart() throws Exception {
if (request != null) {
try {
request.onCompleted();
} catch (IllegalStateException ignored) {
log.info("Ignoring error while stopping {}", ignored + "");
} catch (IllegalStateException e) {
log.info("Ignoring error while stopping {}", e + "");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ public void start() throws Exception {

@Override
public synchronized void close() throws Exception {
if (server != null) server.close(false);
super.close();
if (server != null) {
server.close(false);
}
}

@Override
protected synchronized void stopBeforeRestart() throws Exception {
super.stopBeforeRestart();
if (server != null) server.close(true);
if (server != null) {
server.close(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ public void start() throws Exception {

@Override
public synchronized void close() throws Exception {
if (server != null) server.close(false);
super.close();
if (server != null) {
server.close(false);
}
}

@Override
protected synchronized void stopBeforeRestart() throws Exception {
super.stopBeforeRestart();
if (server != null) server.close(true);
if (server != null) {
server.close(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ public void start() throws Exception {

@Override
public synchronized void close() throws Exception {
if (server != null) server.close(false);
super.close();
if (server != null) {
server.close(false);
}
}

@Override
protected synchronized void stopBeforeRestart() throws Exception {
super.stopBeforeRestart();
if (server != null) server.close(true);
if (server != null) {
server.close(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ public void onNext(ProcessorRequest request) {
public void onError(Throwable throwable) {}

@Override
public void onCompleted() {}
public void onCompleted() {
response.onCompleted();
}
};
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ public void onNext(SinkRequest request) {
public void onError(Throwable throwable) {}

@Override
public void onCompleted() {}
public void onCompleted() {
responseObserver.onCompleted();
}
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ public void onNext(SourceRequest request) {
public void onError(Throwable throwable) {}

@Override
public void onCompleted() {}
public void onCompleted() {
responseObserver.onCompleted();
}
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ default void close() throws Exception {}
/**
* Gracefully restart the agent.
*
* @throws Exception
* @throws Exception if an error occurs
*/
default void restart() throws Exception {}
}

0 comments on commit 230c202

Please sign in to comment.