JsInvokeService - log js body on script failure to investigate easy
This commit is contained in:
parent
ddfb57db58
commit
1d33c09127
@ -120,11 +120,10 @@ public abstract class AbstractJsInvokeService implements JsInvokeService {
|
||||
|
||||
protected abstract long getMaxBlacklistDuration();
|
||||
|
||||
protected void onScriptExecutionError(UUID scriptId, Throwable t) {
|
||||
protected void onScriptExecutionError(UUID scriptId, Throwable t, String scriptBody) {
|
||||
DisableListInfo disableListInfo = disabledFunctions.computeIfAbsent(scriptId, key -> new DisableListInfo());
|
||||
log.warn("Script has exception and will increment counter {} on disabledFunctions for id {}, exception {}, cause {}",
|
||||
disableListInfo.get(), scriptId, t, t.getCause());
|
||||
log.error("onScriptExecutionError", t);
|
||||
log.warn("Script has exception and will increment counter {} on disabledFunctions for id {}, exception {}, cause {}, scriptBody {}",
|
||||
disableListInfo.get(), scriptId, t, t.getCause(), scriptBody);
|
||||
// if (t instanceof TimeoutException || (t.getCause() != null && t.getCause() instanceof TimeoutException)) {
|
||||
// log.warn("Script has TimeoutException and will increment counter {} on disabledFunctions for id {}", //TODO remove after test
|
||||
// disableListInfo.get(),
|
||||
|
||||
@ -160,7 +160,7 @@ public abstract class AbstractNashornJsInvokeService extends AbstractJsInvokeSer
|
||||
return ((Invocable) engine).invokeFunction(functionName, args);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
onScriptExecutionError(scriptId, e);
|
||||
onScriptExecutionError(scriptId, e, functionName);
|
||||
throw new ExecutionException(e);
|
||||
}
|
||||
});
|
||||
|
||||
@ -18,7 +18,6 @@ package org.thingsboard.server.service.script;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -161,7 +160,8 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
|
||||
|
||||
@Override
|
||||
protected ListenableFuture<Object> doInvokeFunction(UUID scriptId, String functionName, Object[] args) {
|
||||
String scriptBody = scriptIdToBodysMap.get(scriptId);
|
||||
log.trace("doInvokeFunction js-request for uuid {} with timeout {}ms", scriptId, maxRequestsTimeout);
|
||||
final String scriptBody = scriptIdToBodysMap.get(scriptId);
|
||||
if (scriptBody == null) {
|
||||
return Futures.immediateFailedFuture(new RuntimeException("No script body found for scriptId: [" + scriptId + "]!"));
|
||||
}
|
||||
@ -170,7 +170,7 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
|
||||
.setScriptIdLSB(scriptId.getLeastSignificantBits())
|
||||
.setFunctionName(functionName)
|
||||
.setTimeout((int) maxRequestsTimeout)
|
||||
.setScriptBody(scriptIdToBodysMap.get(scriptId));
|
||||
.setScriptBody(scriptBody);
|
||||
|
||||
for (Object arg : args) {
|
||||
jsRequestBuilder.addArgs(arg.toString());
|
||||
@ -193,7 +193,7 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
onScriptExecutionError(scriptId, t);
|
||||
onScriptExecutionError(scriptId, t, scriptBody);
|
||||
if (t instanceof TimeoutException || (t.getCause() != null && t.getCause() instanceof TimeoutException)) {
|
||||
queueTimeoutMsgs.incrementAndGet();
|
||||
}
|
||||
@ -206,7 +206,7 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
|
||||
return invokeResult.getResult();
|
||||
} else {
|
||||
final RuntimeException e = new RuntimeException(invokeResult.getErrorDetails());
|
||||
onScriptExecutionError(scriptId, e);
|
||||
onScriptExecutionError(scriptId, e, scriptBody);
|
||||
log.debug("[{}] Failed to compile script due to [{}]: {}", scriptId, invokeResult.getErrorCode().name(), invokeResult.getErrorDetails());
|
||||
throw e;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user