-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-python-exec.java
More file actions
44 lines (37 loc) · 1.74 KB
/
Copy pathtest-python-exec.java
File metadata and controls
44 lines (37 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.sensorvision.model.FunctionRuntime;
import org.sensorvision.model.Organization;
import org.sensorvision.model.ServerlessFunction;
import org.sensorvision.service.functions.FunctionExecutionResult;
import org.sensorvision.service.functions.PythonFunctionExecutor;
public class TestPythonExec {
public static void main(String[] args) throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
PythonFunctionExecutor executor = new PythonFunctionExecutor(objectMapper);
String pythonCode = """
def main(event):
return {"result": "Hello from Python", "input": event}
""";
Organization org = new Organization();
org.setId(1L);
org.setName("Test Org");
ServerlessFunction function = new ServerlessFunction();
function.setId(1L);
function.setOrganization(org);
function.setName("test-function");
function.setRuntime(FunctionRuntime.PYTHON_3_11);
function.setCode(pythonCode);
function.setHandler("main");
function.setTimeoutSeconds(30);
function.setMemoryLimitMb(512);
function.setEnabled(true);
JsonNode input = objectMapper.readTree("{\"value\": 42}");
FunctionExecutionResult result = executor.execute(function, input);
System.out.println("Success: " + result.isSuccess());
System.out.println("Output: " + result.getOutput());
System.out.println("Error Message: " + result.getErrorMessage());
System.out.println("Error Stack: " + result.getErrorStack());
System.out.println("Duration: " + result.getDurationMs() + "ms");
}
}