From 82f9eed985466340efa83a05060262e18c1ba2c2 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Tue, 5 Jul 2022 17:22:11 +0300 Subject: [PATCH] Add handling of failed remote js responses. Do not block script due to timeout message because of queue connectivity --- .../service/script/RemoteJsInvokeService.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/script/RemoteJsInvokeService.java b/application/src/main/java/org/thingsboard/server/service/script/RemoteJsInvokeService.java index 3bee5ca720..27ee22e459 100644 --- a/application/src/main/java/org/thingsboard/server/service/script/RemoteJsInvokeService.java +++ b/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>() { @Override public void onSuccess(@Nullable TbProtoQueueMsg 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(); }