Skip to content

Commit

Permalink
Merge pull request #1405 from CloudSlang/check_if_alive
Browse files Browse the repository at this point in the history
Check if python executor is alive before attempting to run
  • Loading branch information
QueueUpX authored Feb 16, 2023
2 parents 139e3e6 + 07600d1 commit ca697a4
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.cloudslang.lang.entities.bindings.values.ValueFactory;
import io.cloudslang.lang.runtime.services.ScriptsService;
import io.cloudslang.runtime.api.python.PythonEvaluationResult;
import io.cloudslang.runtime.api.python.PythonExecutorLifecycleManagerService;
import io.cloudslang.runtime.api.python.PythonRuntimeService;
import io.cloudslang.runtime.api.python.enums.PythonStrategy;
import io.cloudslang.runtime.impl.python.external.ExternalPythonScriptException;
Expand Down Expand Up @@ -70,6 +71,9 @@ public class ScriptEvaluator extends ScriptProcessor {
@Autowired
private ScriptsService scriptsService;

@Autowired
private PythonExecutorLifecycleManagerService pythonExecutorLifecycleManagerService;

public Value evalExpr(String expr, Map<String, Value> context, Set<SystemProperty> systemProperties,
Set<ScriptFunction> functionDependencies) {
try {
Expand Down Expand Up @@ -148,13 +152,18 @@ private Value doEvaluateExpressionPythonExecutor(String expr,
}

PythonEvaluationResult result;
try {
result = pythonExecutorService.eval(
buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext);
} catch (ExternalPythonScriptException exception) {
if (logger.isDebugEnabled()) {
logger.warn("Could not evaluate expressions on python executor, retrying with python");
if (pythonExecutorLifecycleManagerService.isAlive()) {
try {
result = pythonExecutorService.eval(
buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext);
} catch (ExternalPythonScriptException exception) {
if (logger.isDebugEnabled()) {
logger.warn("Could not evaluate expressions on python executor, retrying with python");
}
result = pythonRuntimeService.eval(
buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext);
}
} else {
result = pythonRuntimeService.eval(
buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext);
}
Expand Down

0 comments on commit ca697a4

Please sign in to comment.