feat: implement Validate to check for cycle

This commit is contained in:
sujit
2024-10-22 12:40:14 +05:45
parent a84ff6d831
commit ea0a7022f9
6 changed files with 83 additions and 75 deletions

View File

@@ -5,8 +5,6 @@ import (
"github.com/oarkflow/json"
"github.com/oarkflow/dipper"
"github.com/oarkflow/mq"
"github.com/oarkflow/mq/services"
)
@@ -109,38 +107,3 @@ func (e *InAppNotification) ProcessTask(ctx context.Context, task *mq.Task) mq.R
}
return mq.Result{Payload: task.Payload, Ctx: ctx}
}
type DataBranchHandler struct{ services.Operation }
func (v *DataBranchHandler) ProcessTask(ctx context.Context, task *mq.Task) mq.Result {
ctx = context.WithValue(ctx, "extra_params", map[string]any{"iphone": true})
var row map[string]any
var result mq.Result
result.Payload = task.Payload
err := json.Unmarshal(result.Payload, &row)
if err != nil {
result.Error = err
return result
}
b := make(map[string]any)
switch branches := row["data_branch"].(type) {
case map[string]any:
for field, handler := range branches {
data, err := dipper.Get(row, field)
if err != nil {
break
}
b[handler.(string)] = data
}
break
}
br, err := json.Marshal(b)
if err != nil {
result.Error = err
return result
}
result.Status = "branches"
result.Payload = br
result.Ctx = ctx
return result
}