Browse Source

Add handling of failed remote js responses. Do not block script due to timeout message because of queue connectivity

pull/6882/head
Volodymyr Babak 4 years ago
parent
commit
82f9eed985
  1. 23
      application/src/main/java/org/thingsboard/server/service/script/RemoteJsInvokeService.java

23
application/src/main/java/org/thingsboard/server/service/script/RemoteJsInvokeService.java

@ -192,14 +192,33 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
Futures.addCallback(future, new FutureCallback<TbProtoQueueMsg<JsInvokeProtos.RemoteJsResponse>>() {
@Override
public void onSuccess(@Nullable TbProtoQueueMsg<JsInvokeProtos.RemoteJsResponse> result) {
queueInvokeMsgs.incrementAndGet();
if (result == null) {
queueInvokeMsgs.incrementAndGet();
} else {
JsInvokeProtos.JsInvokeResponse invokeResponse = result.getValue().getInvokeResponse();
if (invokeResponse.getSuccess()) {
queueInvokeMsgs.incrementAndGet();
} else {
JsInvokeProtos.JsInvokeErrorCode errorCode = invokeResponse.getErrorCode();
final RuntimeException e = new RuntimeException(invokeResponse.getErrorDetails());
onScriptExecutionError(scriptId, e, scriptBody);
if (JsInvokeProtos.JsInvokeErrorCode.TIMEOUT_ERROR.equals(errorCode)) {
queueTimeoutMsgs.incrementAndGet();
queueFailedMsgs.incrementAndGet();
} else if (JsInvokeProtos.JsInvokeErrorCode.COMPILATION_ERROR.equals(errorCode)
|| JsInvokeProtos.JsInvokeErrorCode.RUNTIME_ERROR.equals(errorCode)) {
queueFailedMsgs.incrementAndGet();
}
}
}
}
@Override
public void onFailure(Throwable t) {
onScriptExecutionError(scriptId, t, scriptBody);
if (t instanceof TimeoutException || (t.getCause() != null && t.getCause() instanceof TimeoutException)) {
queueTimeoutMsgs.incrementAndGet();
} else {
onScriptExecutionError(scriptId, t, scriptBody);
}
queueFailedMsgs.incrementAndGet();
}

Loading…
Cancel
Save