use of net.robinfriedli.aiode.entities.StoredScript in project aiode by robinfriedli.
the class SafeGroovyScriptRunner method runScripts.
/**
* Run all provided scripts sequentially in the same thread. This counts as one single script execution, thus all scripts
* share the same method invocation limits and run with one time limit. This method is mainly used by the ScriptCommandInterceptor
* to run all interceptors or all finalizers. Just like {@link #evaluateScript(String, long, TimeUnit)} this applies
* all security checks and expression transformation if isPrivileged is false.
*
* @param scripts a list of {@link StoredScript} entities representing the scripts to run
* @param currentScript a reference pointing to the script that is currently being executed, can be used to reference
* the last executed script if execution fails or execution runs into a timeout
* @param timeout the time delta in which all provided scripts have to run, ignored if isPrivileged is true
* @param timeUnit the time unit of the timeout
* @throws ExecutionException if a script fails due to an exception
* @throws TimeoutException if not all scripts finish within the given time limit
*/
public void runScripts(List<StoredScript> scripts, AtomicReference<StoredScript> currentScript, long timeout, TimeUnit timeUnit) throws ExecutionException, TimeoutException {
GroovyShell groovyShell = createShell();
Future<Object> result = scriptExecution(() -> {
for (StoredScript script : scripts) {
currentScript.set(script);
groovyShell.evaluate(script.getScript());
}
return null;
});
runScriptWithTimeout(result, timeout, timeUnit);
}
Aggregations