BUG: Fixed resource overload when getting workflows
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
NAME=shuffle-app_sdk
|
NAME=shuffle-app_sdk
|
||||||
VERSION=0.8.4
|
VERSION=0.8.41
|
||||||
|
|
||||||
docker rmi docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION --force
|
docker rmi docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION --force
|
||||||
docker build . -t frikky/shuffle:app_sdk -t frikky/$NAME:$VERSION -t docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION -t ghcr.io/frikky/$NAME:$VERSION
|
docker build . -t frikky/shuffle:app_sdk -t frikky/$NAME:$VERSION -t docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION -t ghcr.io/frikky/$NAME:$VERSION
|
||||||
|
|||||||
@@ -501,7 +501,7 @@ func handleStopHookDocker(resp http.ResponseWriter, request *http.Request) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
hook, err := getHook(ctx, fileId)
|
hook, err := getHook(ctx, fileId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed getting hook: %s", err)
|
log.Printf("Failed getting hook %s (stop docker): %s", fileId, err)
|
||||||
resp.WriteHeader(401)
|
resp.WriteHeader(401)
|
||||||
resp.Write([]byte(`{"success": false}`))
|
resp.Write([]byte(`{"success": false}`))
|
||||||
return
|
return
|
||||||
@@ -633,7 +633,7 @@ func handleStartHookDocker(resp http.ResponseWriter, request *http.Request) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
hook, err := getHook(ctx, fileId)
|
hook, err := getHook(ctx, fileId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed getting hook: %s", err)
|
log.Printf("Failed getting hook %s (start docker): %s", fileId, err)
|
||||||
resp.WriteHeader(401)
|
resp.WriteHeader(401)
|
||||||
resp.Write([]byte(`{"success": false}`))
|
resp.Write([]byte(`{"success": false}`))
|
||||||
return
|
return
|
||||||
@@ -781,7 +781,7 @@ func hookTest() {
|
|||||||
|
|
||||||
returnHook, err := getHook(ctx, hook.Id)
|
returnHook, err := getHook(ctx, hook.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed getting hook: %s", err)
|
log.Printf("Failed getting hook %s (test): %s", hook.Id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(returnHook.Id) > 0 {
|
if len(returnHook.Id) > 0 {
|
||||||
|
|||||||
+33
-28
@@ -3096,7 +3096,7 @@ func handleSetHook(resp http.ResponseWriter, request *http.Request) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
_, err = getHook(ctx, workflowId)
|
_, err = getHook(ctx, workflowId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed getting hook: %s", err)
|
log.Printf("Failed getting hook %s (set): %s", workflowId, err)
|
||||||
resp.WriteHeader(401)
|
resp.WriteHeader(401)
|
||||||
resp.Write([]byte(`{"success": false, "message": "Invalid ID"}`))
|
resp.Write([]byte(`{"success": false, "message": "Invalid ID"}`))
|
||||||
return
|
return
|
||||||
@@ -3457,7 +3457,7 @@ func handleWebhookCallback(resp http.ResponseWriter, request *http.Request) {
|
|||||||
//log.Printf("HookID: %s", hookId)
|
//log.Printf("HookID: %s", hookId)
|
||||||
hook, err := getHook(ctx, hookId)
|
hook, err := getHook(ctx, hookId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed getting hook: %s", err)
|
log.Printf("Failed getting hook %s (callback): %s", hookId, err)
|
||||||
resp.WriteHeader(401)
|
resp.WriteHeader(401)
|
||||||
resp.Write([]byte(`{"success": false}`))
|
resp.Write([]byte(`{"success": false}`))
|
||||||
return
|
return
|
||||||
@@ -3470,7 +3470,7 @@ func handleWebhookCallback(resp http.ResponseWriter, request *http.Request) {
|
|||||||
//resp.WriteHeader(200)
|
//resp.WriteHeader(200)
|
||||||
//resp.Write([]byte(`{"success": true}`))
|
//resp.Write([]byte(`{"success": true}`))
|
||||||
if hook.Status == "stopped" {
|
if hook.Status == "stopped" {
|
||||||
log.Printf("Not running because hook status is stopped")
|
log.Printf("Not running %s because hook status is stopped", hook.Id)
|
||||||
resp.WriteHeader(401)
|
resp.WriteHeader(401)
|
||||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "The webhook isn't running. Click start to start it"}`)))
|
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "The webhook isn't running. Click start to start it"}`)))
|
||||||
return
|
return
|
||||||
@@ -3493,20 +3493,34 @@ func handleWebhookCallback(resp http.ResponseWriter, request *http.Request) {
|
|||||||
ExecutionArgument string `json:"execution_argument"`
|
ExecutionArgument string `json:"execution_argument"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(request.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Body data error: %s", err)
|
||||||
|
resp.WriteHeader(401)
|
||||||
|
resp.Write([]byte(`{"success": false}`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
newBody := ExecutionStruct{
|
||||||
|
Start: hook.Start,
|
||||||
|
ExecutionSource: "webhook",
|
||||||
|
ExecutionArgument: string(body),
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := json.Marshal(newBody)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed newBody marshaling: %s", err)
|
||||||
|
resp.WriteHeader(401)
|
||||||
|
resp.Write([]byte(`{"success": false}`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, item := range hook.Workflows {
|
for _, item := range hook.Workflows {
|
||||||
log.Printf("Running webhook for workflow %s with startnode %s", item, hook.Start)
|
log.Printf("Running webhook for workflow %s with startnode %s", item, hook.Start)
|
||||||
workflow := Workflow{
|
workflow := Workflow{
|
||||||
ID: "",
|
ID: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(request.Body)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Body data error: %s", err)
|
|
||||||
resp.WriteHeader(401)
|
|
||||||
resp.Write([]byte(`{"success": false}`))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//parsedBody := string(body)
|
//parsedBody := string(body)
|
||||||
//parsedBody = strings.Replace(parsedBody, "\"", "\\\"", -1)
|
//parsedBody = strings.Replace(parsedBody, "\"", "\\\"", -1)
|
||||||
//if len(parsedBody) > 0 {
|
//if len(parsedBody) > 0 {
|
||||||
@@ -3515,20 +3529,6 @@ func handleWebhookCallback(resp http.ResponseWriter, request *http.Request) {
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
newBody := ExecutionStruct{
|
|
||||||
Start: hook.Start,
|
|
||||||
ExecutionSource: "webhook",
|
|
||||||
ExecutionArgument: string(body),
|
|
||||||
}
|
|
||||||
|
|
||||||
b, err := json.Marshal(newBody)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Failed newBody marshaling: %s", err)
|
|
||||||
resp.WriteHeader(401)
|
|
||||||
resp.Write([]byte(`{"success": false}`))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//bodyWrapper := fmt.Sprintf(`{"start": "%s", "execution_source": "webhook", "execution_argument": "%s"}`, hook.Start, string(parsedBody))
|
//bodyWrapper := fmt.Sprintf(`{"start": "%s", "execution_source": "webhook", "execution_argument": "%s"}`, hook.Start, string(parsedBody))
|
||||||
//if len(hook.Start) == 0 {
|
//if len(hook.Start) == 0 {
|
||||||
// log.Printf("No start node for hook %s - running with workflow default.", hook.Id)
|
// log.Printf("No start node for hook %s - running with workflow default.", hook.Id)
|
||||||
@@ -3798,7 +3798,7 @@ func sendHookResult(resp http.ResponseWriter, request *http.Request) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
hook, err := getHook(ctx, workflowId)
|
hook, err := getHook(ctx, workflowId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed getting hook: %s", err)
|
log.Printf("Failed getting hook %s (send): %s", workflowId, err)
|
||||||
resp.WriteHeader(401)
|
resp.WriteHeader(401)
|
||||||
resp.Write([]byte(`{"success": false}`))
|
resp.Write([]byte(`{"success": false}`))
|
||||||
return
|
return
|
||||||
@@ -3865,7 +3865,7 @@ func handleGetHook(resp http.ResponseWriter, request *http.Request) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
hook, err := getHook(ctx, workflowId)
|
hook, err := getHook(ctx, workflowId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed getting hook: %s", err)
|
log.Printf("Failed getting hook %s (get hook): %s", workflowId, err)
|
||||||
resp.WriteHeader(401)
|
resp.WriteHeader(401)
|
||||||
resp.Write([]byte(`{"success": false}`))
|
resp.Write([]byte(`{"success": false}`))
|
||||||
return
|
return
|
||||||
@@ -7152,7 +7152,12 @@ func runInit(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Found %d users.", len(users))
|
if len(users) == 1 {
|
||||||
|
log.Printf("Found 1 user - %s.", users[0].Username)
|
||||||
|
} else {
|
||||||
|
log.Printf("Found %d users.", len(users))
|
||||||
|
}
|
||||||
|
|
||||||
if len(activeOrgs) == 1 && len(users) > 0 {
|
if len(activeOrgs) == 1 && len(users) > 0 {
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
if user.ActiveOrg.Id == "" && len(user.Username) > 0 {
|
if user.ActiveOrg.Id == "" && len(user.Username) > 0 {
|
||||||
|
|||||||
@@ -1281,8 +1281,11 @@ func runWorkflowExecutionTransaction(ctx context.Context, attempts int64, workfl
|
|||||||
// Prevents timing issues
|
// Prevents timing issues
|
||||||
//ExecutionId
|
//ExecutionId
|
||||||
if _, err := tx.Put(key, workflowExecution); err != nil {
|
if _, err := tx.Put(key, workflowExecution); err != nil {
|
||||||
tx.Rollback()
|
log.Printf("[ERROR] tx.Put error: %v", err)
|
||||||
log.Printf("[ERROR] tx.Put bug: %v", err)
|
err = tx.Rollback()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("[ERROR] Rollback error (3): %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
resp.WriteHeader(401)
|
resp.WriteHeader(401)
|
||||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Failed setting workflowexecution actionresult: %s"}`, err)))
|
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Failed setting workflowexecution actionresult: %s"}`, err)))
|
||||||
@@ -1290,9 +1293,14 @@ func runWorkflowExecutionTransaction(ctx context.Context, attempts int64, workfl
|
|||||||
}
|
}
|
||||||
|
|
||||||
if _, err = tx.Commit(); err != nil {
|
if _, err = tx.Commit(); err != nil {
|
||||||
|
err = tx.Rollback()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("[ERROR] Rollback error expected ? (1): %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
if attempts >= 7 {
|
if attempts >= 7 {
|
||||||
log.Printf("[ERROR] QUITTING: tx.Commit %d: %v", attempts, err)
|
log.Printf("[ERROR] QUITTING: tx.Commit %d: %v", attempts, err)
|
||||||
tx.Rollback()
|
|
||||||
workflowExecution.Status = "ABORTED"
|
workflowExecution.Status = "ABORTED"
|
||||||
setWorkflowExecution(ctx, *workflowExecution)
|
setWorkflowExecution(ctx, *workflowExecution)
|
||||||
|
|
||||||
@@ -1308,6 +1316,11 @@ func runWorkflowExecutionTransaction(ctx context.Context, attempts int64, workfl
|
|||||||
attempts += 1
|
attempts += 1
|
||||||
runWorkflowExecutionTransaction(ctx, attempts, workflowExecutionId, actionResult, resp)
|
runWorkflowExecutionTransaction(ctx, attempts, workflowExecutionId, actionResult, resp)
|
||||||
return
|
return
|
||||||
|
} else {
|
||||||
|
//if grpc.Code(err) == codes.Aborted {
|
||||||
|
// return nil, ErrConcurrentTransaction
|
||||||
|
//}
|
||||||
|
//t.id = nil // mark the transaction as expired
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.WriteHeader(200)
|
resp.WriteHeader(200)
|
||||||
@@ -6093,7 +6106,7 @@ func handleStopHook(resp http.ResponseWriter, request *http.Request) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
hook, err := getHook(ctx, fileId)
|
hook, err := getHook(ctx, fileId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed getting hook: %s", err)
|
log.Printf("Failed getting hook %s (stop): %s", fileId, err)
|
||||||
resp.WriteHeader(401)
|
resp.WriteHeader(401)
|
||||||
resp.Write([]byte(`{"success": false}`))
|
resp.Write([]byte(`{"success": false}`))
|
||||||
return
|
return
|
||||||
@@ -6176,7 +6189,7 @@ func handleDeleteHook(resp http.ResponseWriter, request *http.Request) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
hook, err := getHook(ctx, fileId)
|
hook, err := getHook(ctx, fileId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed getting hook: %s", err)
|
log.Printf("Failed getting hook %s (delete): %s", fileId, err)
|
||||||
resp.WriteHeader(401)
|
resp.WriteHeader(401)
|
||||||
resp.Write([]byte(`{"success": false}`))
|
resp.Write([]byte(`{"success": false}`))
|
||||||
return
|
return
|
||||||
@@ -6317,7 +6330,7 @@ func handleStartHook(resp http.ResponseWriter, request *http.Request) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
hook, err := getHook(ctx, fileId)
|
hook, err := getHook(ctx, fileId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed getting hook: %s", err)
|
log.Printf("Failed getting hook %s (start): %s", fileId, err)
|
||||||
resp.WriteHeader(401)
|
resp.WriteHeader(401)
|
||||||
resp.Write([]byte(`{"success": false}`))
|
resp.Write([]byte(`{"success": false}`))
|
||||||
return
|
return
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@ services:
|
|||||||
- backend
|
- backend
|
||||||
backend:
|
backend:
|
||||||
#build: ./backend
|
#build: ./backend
|
||||||
image: ghcr.io/frikky/shuffle-backend:0.8.43
|
image: ghcr.io/frikky/shuffle-backend:0.8.44
|
||||||
container_name: shuffle-backend
|
container_name: shuffle-backend
|
||||||
hostname: ${BACKEND_HOSTNAME}
|
hostname: ${BACKEND_HOSTNAME}
|
||||||
# Here for debugging:
|
# Here for debugging:
|
||||||
|
|||||||
@@ -4370,7 +4370,7 @@ const AngularWorkflow = (props) => {
|
|||||||
conditionValue.value = "contains_any_of"
|
conditionValue.value = "contains_any_of"
|
||||||
setConditionValue(conditionValue)
|
setConditionValue(conditionValue)
|
||||||
setVariableAnchorEl(null)
|
setVariableAnchorEl(null)
|
||||||
}} key={"contains_any_of"}>contains</MenuItem>
|
}} key={"contains_any_of"}>contains any of</MenuItem>
|
||||||
<MenuItem style={menuItemStyle} onClick={(e) => {
|
<MenuItem style={menuItemStyle} onClick={(e) => {
|
||||||
conditionValue.value = "matches regex"
|
conditionValue.value = "matches regex"
|
||||||
setConditionValue(conditionValue)
|
setConditionValue(conditionValue)
|
||||||
@@ -5979,7 +5979,7 @@ const AngularWorkflow = (props) => {
|
|||||||
{workflowExecutions.length > 0 ?
|
{workflowExecutions.length > 0 ?
|
||||||
<div>
|
<div>
|
||||||
{workflowExecutions.map(data => {
|
{workflowExecutions.map(data => {
|
||||||
const statusColor = data.status === "FINISHED" ? "green" : data.status === "ABORTED" ? "red" : "orange"
|
const statusColor = data.status === "FINISHED" ? "green" : data.status === "ABORTED" || data.status === "FAILED" ? "red" : "orange"
|
||||||
const timeElapsed = data.completed_at-data.started_at
|
const timeElapsed = data.completed_at-data.started_at
|
||||||
const resultsLength = data.results !== undefined && data.results !== null ? data.results.length : 0
|
const resultsLength = data.results !== undefined && data.results !== null ? data.results.length : 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user