Continuing forparser for app_sdk

This commit is contained in:
frikky
2020-05-20 11:06:22 +02:00
parent 5d092ddd41
commit c557d232c9
9 changed files with 333 additions and 98 deletions
+12 -7
View File
@@ -122,9 +122,11 @@ class AppBase:
baseresult = execution_data["execution_argument"]
else:
for result in execution_data["results"]:
if result["action"]["label"].lower() == actionname.lower():
resultlabel = result["action"]["label"].replace(" ", "_", -1)
if resultlabel.lower() == actionname.lower():
baseresult = result["result"]
break
except KeyError as error:
print(f"Error: {error}")
@@ -143,9 +145,14 @@ class AppBase:
basejson = json.loads(baseresult)
except json.decoder.JSONDecodeError as e:
return baseresult
def loop_recursion(data):
for value in data:
pass
try:
for value in parsersplit[1:]:
print("VALUE: %s", value)
if value == "#":
print("HANDLE RECURSIVE LOOP")
pass
@@ -177,7 +184,7 @@ class AppBase:
data = parameter["value"]
self.logger.debug(f"\n\nHandle static data with JSON: {data}\n\n")
match = ".*([$]{1}(\w+\.?){1,})"
match = ".*([$]{1}([a-zA-Z0-9()# _-]+\.?){1,})"
actualitem = re.findall(match, data, re.MULTILINE)
self.logger.info("PARSED: %s" % actualitem)
if len(actualitem) > 0:
@@ -450,17 +457,15 @@ class AppBase:
calltimes = 1
result = ""
paramiter = []
for parameter in action["parameters"]:
#self.logger.info(parameter)
#print(fullexecution)
all_executions = []
for parameter in action["parameters"]:
check, value = parse_params(action, fullexecution, parameter)
if check:
raise Exception(check)
if isinstance(value, list):
params[parameter["name"]] = value
# p["value"]
# FIXME - this is horrible, but works for now
#for i in range(calltimes):
Binary file not shown.
+24 -2
View File
@@ -78,6 +78,7 @@ type WorkflowExecution struct {
type Action struct {
AppName string `json:"app_name" datastore:"app_name"`
AppVersion string `json:"app_version" datastore:"app_version"`
AppID string `json:"app_id" datastore:"app_id"`
Errors []string `json:"errors" datastore:"errors"`
ID string `json:"id" datastore:"id"`
IsValid bool `json:"is_valid" datastore:"is_valid"`
@@ -258,7 +259,7 @@ func shutdown(executionId, workflowId string) {
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", authorization)
//req.Header.Add("Authorization", authorization)
client := &http.Client{}
_, err = client.Do(req)
if err != nil {
@@ -336,6 +337,21 @@ func removeContainer(containername string) error {
return nil
}
func runFilter(workflowExecution WorkflowExecution, action Action) {
// 1. Get the parameter $.#.id
if action.Label == "filter_cases" && len(action.Parameters) > 0 {
if action.Parameters[0].Variant == "ACTION_RESULT" {
param := action.Parameters[0]
value := param.Value
// Loop cases.. Hmm, that's tricky
}
} else {
log.Printf("No handler for filter %s with %d params", action.Label, len(action.Parameters))
}
}
func handleExecution(client *http.Client, req *http.Request, workflowExecution WorkflowExecution) error {
// if no onprem runs (shouldn't happen, but extra check), exit
// if there are some, load the images ASAP for the app
@@ -364,7 +380,6 @@ func handleExecution(client *http.Client, req *http.Request, workflowExecution W
}
toExecuteOnprem = append(toExecuteOnprem, action.ID)
actionName := fmt.Sprintf("%s:%s_%s", baseimagename, action.AppName, action.AppVersion)
found := false
for _, app := range onpremApps {
@@ -555,12 +570,19 @@ func handleExecution(client *http.Client, req *http.Request, workflowExecution W
// marshal action and put it in there rofl
log.Printf("Time to execute %s with app %s:%s, function %s, env %s with %d parameters.", action.ID, action.AppName, action.AppVersion, action.Name, action.Environment, len(action.Parameters))
actionData, err := json.Marshal(action)
if err != nil {
log.Printf("Failed unmarshalling action: %s", err)
continue
}
if action.AppID == "0ca8887e-b4af-4e3e-887c-87e9d3bc3d3e" {
log.Printf("\nShould run filter: %#v\n\n", action)
runFilter(workflowExecution, action)
continue
}
//log.Println(string(actionData))
// FIXME - add proper FUNCTION_APIKEY from user definition
env := []string{