@ -30,6 +30,7 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.concurrent.Executors ;
import java.util.concurrent.Executors ;
import java.util.concurrent.ScheduledExecutorService ;
import java.util.concurrent.ScheduledExecutorService ;
import java.util.concurrent.TimeoutException ;
import java.util.concurrent.atomic.AtomicInteger ;
import java.util.concurrent.atomic.AtomicInteger ;
/ * *
/ * *
@ -84,8 +85,10 @@ public abstract class AbstractJsInvokeService implements JsInvokeService {
apiUsageClient . report ( tenantId , customerId , ApiUsageRecordKey . JS_EXEC_COUNT , 1 ) ;
apiUsageClient . report ( tenantId , customerId , ApiUsageRecordKey . JS_EXEC_COUNT , 1 ) ;
return doInvokeFunction ( scriptId , functionName , args ) ;
return doInvokeFunction ( scriptId , functionName , args ) ;
} else {
} else {
return Futures . immediateFailedFuture (
String message = "Script invocation is blocked due to maximum error count "
new RuntimeException ( "Script invocation is blocked due to maximum error count " + getMaxErrors ( ) + "!" ) ) ;
+ getMaxErrors ( ) + ", scriptId " + scriptId + "!" ;
log . warn ( message ) ;
return Futures . immediateFailedFuture ( new RuntimeException ( message ) ) ;
}
}
} else {
} else {
return Futures . immediateFailedFuture ( new RuntimeException ( "JS Execution is disabled due to API limits!" ) ) ;
return Futures . immediateFailedFuture ( new RuntimeException ( "JS Execution is disabled due to API limits!" ) ) ;
@ -117,7 +120,13 @@ public abstract class AbstractJsInvokeService implements JsInvokeService {
protected abstract long getMaxBlacklistDuration ( ) ;
protected abstract long getMaxBlacklistDuration ( ) ;
protected void onScriptExecutionError ( UUID scriptId ) {
protected void onScriptExecutionError ( UUID scriptId , Throwable t ) {
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
disabledFunctions . computeIfAbsent ( scriptId , key - > new DisableListInfo ( ) ) . get ( ) ,
scriptId ) ;
//return; //timeout is not a good reason to disable function
}
disabledFunctions . computeIfAbsent ( scriptId , key - > new DisableListInfo ( ) ) . incrementAndGet ( ) ;
disabledFunctions . computeIfAbsent ( scriptId , key - > new DisableListInfo ( ) ) . incrementAndGet ( ) ;
}
}