Made saving a workflow fast again

This commit is contained in:
frikky
2021-03-13 06:47:04 +01:00
parent b6dcc01e8f
commit 33ac163ef6
8 changed files with 104 additions and 44 deletions
+10 -2
View File
@@ -481,10 +481,17 @@ class AppBase:
new_params = self.validate_unique_fields(param_multiplier) new_params = self.validate_unique_fields(param_multiplier)
print(f"NEW PARAMS: {new_params}") print(f"NEW PARAMS: {new_params}")
if len(new_params) == 0: if len(new_params) == 0:
print(f"No ID's to handle for validation") print("[WARNING] SHOULD STOP MULTI-EXECUTION BECAUSE FIELDS AREN'T UNIQUE")
action_result["status"] = "SKIPPED"
action_result["result"] = f"All values were non-unique"
action_result["completed_at"] = int(time.time())
self.send_result(action_result, headers, stream_path)
exit()
#return
else: else:
#subparams = new_params #subparams = new_params
print(f"NEW PARAMS: {new_params}") print(f"NEW PARAMS: {new_params}")
param_multiplier = new_params
#print("Returned with newparams of length %d", len(new_params)) #print("Returned with newparams of length %d", len(new_params))
#if isinstance(new_params, list) and len(new_params) == 1: #if isinstance(new_params, list) and len(new_params) == 1:
@@ -1821,14 +1828,15 @@ class AppBase:
if len(itemlist) > curminlength: if len(itemlist) > curminlength:
curminlength = len(itemlist) curminlength = len(itemlist)
except json.decoder.JSONDecodeError as e: except json.decoder.JSONDecodeError as e:
print("JSON Error: %s in %s" % (e, actualitem)) print("JSON Error: %s in %s" % (e, actualitem))
replacements[to_be_replaced] = actualitem replacements[to_be_replaced] = actualitem
#print("In second part of else: %s" % (len(itemlist)))
# This is a result array for JUST this value.. # This is a result array for JUST this value..
# What if there are more? # What if there are more?
print("LENGTH: %d. In second part of else: %s" % (len(itemlist), replacements))
resultarray = [] resultarray = []
for i in range(0, curminlength): for i in range(0, curminlength):
tmpitem = json.loads(json.dumps(parameter["value"])) tmpitem = json.loads(json.dumps(parameter["value"]))
+30 -3
View File
@@ -1105,13 +1105,16 @@ func handleConnect(swagger *openapi3.Swagger, api WorkflowApp, extraParameters [
} }
} }
optionalParameters = append(optionalParameters, WorkflowAppActionParameter{ optionalParameters = append(optionalParameters, WorkflowAppActionParameter{
Name: "ssl_verify", Name: "ssl_verify",
Description: "Check if you want to verify request", Description: "Check if you want to verify request",
Multiline: false, Multiline: false,
Required: false, Required: false,
Example: "True", Example: "True",
Options: []string{
"True",
"False",
},
Schema: SchemaDefinition{ Schema: SchemaDefinition{
Type: "string", Type: "string",
}, },
@@ -1244,10 +1247,14 @@ func handleGet(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wor
optionalParameters = append(optionalParameters, WorkflowAppActionParameter{ optionalParameters = append(optionalParameters, WorkflowAppActionParameter{
Name: "ssl_verify", Name: "ssl_verify",
Description: "Check if you want to verify the SSL certificate request", Description: "Check if you want to verify request",
Multiline: false, Multiline: false,
Required: false, Required: false,
Example: "False - default=True", Example: "True",
Options: []string{
"True",
"False",
},
Schema: SchemaDefinition{ Schema: SchemaDefinition{
Type: "string", Type: "string",
}, },
@@ -1382,6 +1389,10 @@ func handleHead(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wo
Multiline: false, Multiline: false,
Required: false, Required: false,
Example: "True", Example: "True",
Options: []string{
"True",
"False",
},
Schema: SchemaDefinition{ Schema: SchemaDefinition{
Type: "string", Type: "string",
}, },
@@ -1517,6 +1528,10 @@ func handleDelete(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []
Multiline: false, Multiline: false,
Required: false, Required: false,
Example: "True", Example: "True",
Options: []string{
"True",
"False",
},
Schema: SchemaDefinition{ Schema: SchemaDefinition{
Type: "string", Type: "string",
}, },
@@ -1684,6 +1699,10 @@ func handlePost(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wo
Multiline: false, Multiline: false,
Required: false, Required: false,
Example: "True", Example: "True",
Options: []string{
"True",
"False",
},
Schema: SchemaDefinition{ Schema: SchemaDefinition{
Type: "string", Type: "string",
}, },
@@ -1823,6 +1842,10 @@ func handlePatch(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []W
Multiline: false, Multiline: false,
Required: false, Required: false,
Example: "True", Example: "True",
Options: []string{
"True",
"False",
},
Schema: SchemaDefinition{ Schema: SchemaDefinition{
Type: "string", Type: "string",
}, },
@@ -1958,6 +1981,10 @@ func handlePut(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wor
Multiline: false, Multiline: false,
Required: false, Required: false,
Example: "True", Example: "True",
Options: []string{
"True",
"False",
},
Schema: SchemaDefinition{ Schema: SchemaDefinition{
Type: "string", Type: "string",
}, },
+14 -17
View File
@@ -2224,6 +2224,7 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
return return
} }
log.Printf("PRE BODY")
body, err := ioutil.ReadAll(request.Body) body, err := ioutil.ReadAll(request.Body)
if err != nil { if err != nil {
log.Printf("Failed hook unmarshaling: %s", err) log.Printf("Failed hook unmarshaling: %s", err)
@@ -2267,6 +2268,7 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
allNodes := []string{} allNodes := []string{}
workflow.Categories = Categories{} workflow.Categories = Categories{}
log.Printf("PRE APPS")
workflowapps, apperr := getAllWorkflowApps(ctx, 500) workflowapps, apperr := getAllWorkflowApps(ctx, 500)
//log.Printf("Action: %#v", action.Authentication) //log.Printf("Action: %#v", action.Authentication)
@@ -2299,6 +2301,7 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
newActions = append(newActions, action) newActions = append(newActions, action)
} }
log.Printf("PRE SAVECHECK")
if !workflow.PreviouslySaved { if !workflow.PreviouslySaved {
log.Printf("[WORKFLOW INIT] NOT PREVIOUSLY SAVED - SET ACTION AUTH!") log.Printf("[WORKFLOW INIT] NOT PREVIOUSLY SAVED - SET ACTION AUTH!")
//AuthenticationId string `json:"authentication_id,omitempty" datastore:"authentication_id"` //AuthenticationId string `json:"authentication_id,omitempty" datastore:"authentication_id"`
@@ -2434,6 +2437,7 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
workflow.PreviouslySaved = true workflow.PreviouslySaved = true
} }
log.Printf("PRE TRIGGERS")
workflow.Actions = newActions workflow.Actions = newActions
newTriggers := []Trigger{} newTriggers := []Trigger{}
for _, trigger := range workflow.Triggers { for _, trigger := range workflow.Triggers {
@@ -2549,6 +2553,7 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
workflow.Triggers = newTriggers workflow.Triggers = newTriggers
log.Printf("PRE VARIABLES")
for _, variable := range workflow.WorkflowVariables { for _, variable := range workflow.WorkflowVariables {
if len(variable.Value) == 0 { if len(variable.Value) == 0 {
log.Printf("Can't have an empty variable: %s", variable.Name) log.Printf("Can't have an empty variable: %s", variable.Name)
@@ -2596,6 +2601,7 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
} }
// FIXME - append all nodes (actions, triggers etc) to one single array here // FIXME - append all nodes (actions, triggers etc) to one single array here
log.Printf("PRE VARIABLES")
if len(foundNodes) != len(allNodes) || len(workflow.Actions) <= 0 { if len(foundNodes) != len(allNodes) || len(workflow.Actions) <= 0 {
// This shit takes a few seconds lol // This shit takes a few seconds lol
if !workflow.IsValid { if !workflow.IsValid {
@@ -2637,18 +2643,7 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
// Have to do it like this to add the user's apps // Have to do it like this to add the user's apps
//log.Println("Apps set starting") //log.Println("Apps set starting")
//log.Printf("EXIT ON ERROR: %#v", workflow.Configuration.ExitOnError) //log.Printf("EXIT ON ERROR: %#v", workflow.Configuration.ExitOnError)
workflowApps := []WorkflowApp{} //workflowapps, apperr := getAllWorkflowApps(ctx, 500)
//memcacheName = "all_apps"
//if item, err := memcache.Get(ctx, memcacheName); err == memcache.ErrCacheMiss {
// // Not in cache
// log.Printf("Apps not in cache.")
workflowApps, err = getAllWorkflowApps(ctx, 100)
if err != nil {
log.Printf("Failed getting all workflow apps from database: %s", err)
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false}`))
return
}
// Started getting the single apps, but if it's weird, this is faster // Started getting the single apps, but if it's weird, this is faster
// 1. Check workflow.Start // 1. Check workflow.Start
@@ -2680,6 +2675,7 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
} }
// Check every app action and param to see whether they exist // Check every app action and param to see whether they exist
log.Printf("PRE ACTIONS 2")
newActions = []Action{} newActions = []Action{}
for _, action := range workflow.Actions { for _, action := range workflow.Actions {
reservedApps := []string{ reservedApps := []string{
@@ -2731,7 +2727,7 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
} else { } else {
curapp := WorkflowApp{} curapp := WorkflowApp{}
// FIXME - can this work with ONLY AppID? // FIXME - can this work with ONLY AppID?
for _, app := range workflowApps { for _, app := range workflowapps {
if app.ID == action.AppID { if app.ID == action.AppID {
curapp = app curapp = app
break break
@@ -2860,10 +2856,11 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
Errors: workflow.Errors, Errors: workflow.Errors,
} }
cacheKey := fmt.Sprintf("workflowapps-sorted-100") // Really don't know why this was happening
requestCache.Delete(cacheKey) //cacheKey := fmt.Sprintf("workflowapps-sorted-100")
cacheKey = fmt.Sprintf("workflowapps-sorted-500") //requestCache.Delete(cacheKey)
requestCache.Delete(cacheKey) //cacheKey = fmt.Sprintf("workflowapps-sorted-500")
//requestCache.Delete(cacheKey)
log.Printf("[INFO] Saved new version of workflow %s (%s) for org %s", workflow.Name, fileId, workflow.OrgId) log.Printf("[INFO] Saved new version of workflow %s (%s) for org %s", workflow.Name, fileId, workflow.OrgId)
resp.WriteHeader(200) resp.WriteHeader(200)
+2 -2
View File
@@ -2,7 +2,7 @@ version: '3'
services: services:
frontend: frontend:
#build: ./frontend #build: ./frontend
image: ghcr.io/frikky/shuffle-frontend:0.8.62 image: ghcr.io/frikky/shuffle-frontend:0.8.63
container_name: shuffle-frontend container_name: shuffle-frontend
hostname: shuffle-frontend hostname: shuffle-frontend
ports: ports:
@@ -17,7 +17,7 @@ services:
- backend - backend
backend: backend:
#build: ./backend #build: ./backend
image: ghcr.io/frikky/shuffle-backend:0.8.62 image: ghcr.io/frikky/shuffle-backend:0.8.63
container_name: shuffle-backend container_name: shuffle-backend
hostname: ${BACKEND_HOSTNAME} hostname: ${BACKEND_HOSTNAME}
# Here for debugging: # Here for debugging:
+1
View File
@@ -18,6 +18,7 @@ const alertStyle = {
width: 400, width: 400,
boxSizing: 'border-box', boxSizing: 'border-box',
zIndex: 100001, zIndex: 100001,
overflow: "hidden",
} }
const buttonStyle = { const buttonStyle = {
+1 -1
View File
@@ -1958,7 +1958,7 @@ const Admin = (props) => {
primary={new Date(file.created_at*1000).toISOString()} primary={new Date(file.created_at*1000).toISOString()}
/> />
<ListItemText <ListItemText
style={{maxWidth: 150, minWidth: 150}} style={{maxWidth: 150, minWidth: 150, overflow: "hidden",}}
primary={file.filename} primary={file.filename}
/> />
<ListItemText <ListItemText
+7 -5
View File
@@ -569,7 +569,7 @@ const AppCreator = (props) => {
} }
} }
console.log(methodvalue["requestBody"]["content"]) //console.log(methodvalue["requestBody"]["content"])
if (methodvalue["requestBody"]["content"]["multipart/form-data"] !== undefined) { if (methodvalue["requestBody"]["content"]["multipart/form-data"] !== undefined) {
if (methodvalue["requestBody"]["content"]["multipart/form-data"]["schema"] !== undefined && methodvalue["requestBody"]["content"]["multipart/form-data"]["schema"] !== null) { if (methodvalue["requestBody"]["content"]["multipart/form-data"]["schema"] !== undefined && methodvalue["requestBody"]["content"]["multipart/form-data"]["schema"] !== null) {
if (methodvalue["requestBody"]["content"]["multipart/form-data"]["schema"]["type"] === "object") { if (methodvalue["requestBody"]["content"]["multipart/form-data"]["schema"]["type"] === "object") {
@@ -1796,8 +1796,8 @@ const AppCreator = (props) => {
</MenuItem> </MenuItem>
) )
})} })}
{actionBodyRequest.map(data => ( {actionBodyRequest.map((data, index) => (
<MenuItem style={{backgroundColor: inputColor, color: "white"}} value={data}> <MenuItem key={index} style={{backgroundColor: inputColor, color: "white"}} value={data}>
{data} {data}
</MenuItem> </MenuItem>
))} ))}
@@ -1833,8 +1833,8 @@ const AppCreator = (props) => {
console.log("URL: ", parsedurl) console.log("URL: ", parsedurl)
if (parsedurl.includes("<") && parsedurl.includes(">")) { if (parsedurl.includes("<") && parsedurl.includes(">")) {
console.log("REPLACE") console.log("REPLACE")
parsedurl = parsedurl.replace("<", "{") parsedurl = parsedurl.replaceAll("<", "{")
parsedurl = parsedurl.replace(">", "}") parsedurl = parsedurl.replaceAll(">", "}")
} }
if (parsedurl.startsWith("PUT ") || parsedurl.startsWith("GET ") ||parsedurl.startsWith("POST ") || parsedurl.startsWith("DELETE ") ||parsedurl.startsWith("PATCH ") || parsedurl.startsWith("CONNECT ")) { if (parsedurl.startsWith("PUT ") || parsedurl.startsWith("GET ") ||parsedurl.startsWith("POST ") || parsedurl.startsWith("DELETE ") ||parsedurl.startsWith("PATCH ") || parsedurl.startsWith("CONNECT ")) {
@@ -2208,8 +2208,10 @@ const AppCreator = (props) => {
}}/> }}/>
const zoomIn = () => { const zoomIn = () => {
console.log("ZOOOMING IN")
setScale(scale+0.1); setScale(scale+0.1);
} }
const zoomOut = () => { const zoomOut = () => {
setScale(scale-0.1); setScale(scale-0.1);
} }
+39 -14
View File
@@ -202,14 +202,40 @@ const Apps = (props) => {
.then((responseJson) => { .then((responseJson) => {
//console.log("Apps: ", responseJson) //console.log("Apps: ", responseJson)
//responseJson = sortByKey(responseJson, "large_image") //responseJson = sortByKey(responseJson, "large_image")
responseJson = sortByKey(responseJson, "generated") //responseJson = sortByKey(responseJson, "is_valid")
//setFilteredApps(responseJson.filter(app => !internalIds.includes(app.name) && !(!app.activated && app.generated)))
setApps(responseJson) var privateapps = []
setFilteredApps(responseJson) var valid = []
if (responseJson.length > 0) { var invalid = []
setSelectedApp(responseJson[0]) for (var key in responseJson) {
if (responseJson[0].actions !== null && responseJson[0].actions.length > 0) { const app = responseJson[key]
setSelectedAction(responseJson[0].actions[0]) if (app.is_valid && !(!app.activated && app.generated)) {
privateapps.push(app)
} else if (app.private_id !== undefined && app.private_id.length > 0) {
valid.push(app)
} else {
invalid.push(app)
}
}
//console.log(privateapps)
//console.log(valid)
//console.log(invalid)
//console.log(privateapps)
//privateapps.reverse()
privateapps.push(...valid)
privateapps.push(...invalid)
setApps(privateapps)
setFilteredApps(privateapps)
if (privateapps.length > 0) {
if (selectedApp.id === undefined || selectedApp.id === null) {
setSelectedApp(privateapps[0])
}
if (privateapps[0].actions !== null && privateapps[0].actions.length > 0) {
setSelectedAction(privateapps[0].actions[0])
} else { } else {
setSelectedAction({}) setSelectedAction({})
} }
@@ -358,8 +384,7 @@ const Apps = (props) => {
<ButtonBase style={{backgroundColor: theme.palette.inputColor, border: 3}}> <ButtonBase style={{backgroundColor: theme.palette.inputColor, border: 3}}>
{imageline} {imageline}
</ButtonBase> </ButtonBase>
<div style={{marginLeft: "10px", marginTop: "5px", marginBottom: "5px", width: boxWidth, backgroundColor: boxColor}}> <div style={{marginLeft: "10px", marginTop: "5px", marginBottom: "5px", width: boxWidth, backgroundColor: boxColor}}/>
</div>
<Grid container style={{margin: "0px 10px 10px 10px", flex: "1"}}> <Grid container style={{margin: "0px 10px 10px 10px", flex: "1"}}>
<Grid style={{display: "flex", flexDirection: "column", width: "100%"}}> <Grid style={{display: "flex", flexDirection: "column", width: "100%"}}>
<Grid item style={{flex: "1"}}> <Grid item style={{flex: "1"}}>
@@ -957,7 +982,7 @@ const Apps = (props) => {
setValidation(true) setValidation(true)
setIsLoading(true) setIsLoading(true)
start() //start()
const parsedData = { const parsedData = {
"url": url, "url": url,
@@ -989,10 +1014,10 @@ const Apps = (props) => {
if (response.status === 200) { if (response.status === 200) {
alert.success("Loaded existing apps!") alert.success("Loaded existing apps!")
} }
setIsLoading(false)
stop()
setValidation(false)
//stop()
setIsLoading(false)
setValidation(false)
return response.json() return response.json()
}) })
.then((responseJson) => { .then((responseJson) => {
@@ -1005,7 +1030,7 @@ const Apps = (props) => {
console.log("ERROR: ", error.toString()) console.log("ERROR: ", error.toString())
alert.error(error.toString()) alert.error(error.toString())
stop() //stop()
setIsLoading(false) setIsLoading(false)
setValidation(false) setValidation(false)
}) })