Search workflow in processer via handle also

This commit is contained in:
Peter Grlica
2023-01-16 11:16:49 +01:00
parent f74237dbc5
commit 11dccaea9f
2 changed files with 29 additions and 4 deletions
+22 -2
View File
@@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"github.com/cortezaproject/corteza/server/automation/automation"
atypes "github.com/cortezaproject/corteza/server/automation/types"
@@ -31,6 +32,7 @@ type (
WfExecer interface {
Load(ctx context.Context) error
Exec(ctx context.Context, workflowID uint64, p atypes.WorkflowExecParams) (*expr.Vars, uint64, atypes.Stacktrace, error)
Search(ctx context.Context, filter atypes.WorkflowFilter) (atypes.WorkflowSet, atypes.WorkflowFilter, error)
}
processerPayload struct {
@@ -84,12 +86,30 @@ func (h workflow) Meta() types.FilterMeta {
}
func (h *workflow) Merge(params []byte) (types.Handler, error) {
err := json.NewDecoder(bytes.NewBuffer(params)).Decode(&h.params)
var (
t = struct {
Workflow string `json:"workflow"`
}{}
)
err := json.NewDecoder(bytes.NewBuffer(params)).Decode(&t)
if err != nil {
return h, err
}
i, err := strconv.Atoi(t.Workflow)
if err == nil {
h.params.Workflow = uint64(i)
return h, h.d.Load(context.Background())
}
if wf, _, err := h.d.Search(context.Background(), atypes.WorkflowFilter{Query: fmt.Sprintf("handle='%s'", t.Workflow)}); err != nil {
return h, err
} else {
h.params.Workflow = wf[0].ID
}
// preload workflow cache
return h, h.d.Load(context.Background())
}
@@ -145,7 +165,7 @@ func (h workflow) Handler() types.HandlerFunc {
scope = filterScope(scope, "eventType", "resourceType", "invoker")
// update scope for next items in pipeline
r.WithContext(agctx.ScopeToContext(ctx, scope))
_ = r.WithContext(agctx.ScopeToContext(ctx, scope))
return nil
}
+7 -2
View File
@@ -23,8 +23,9 @@ import (
type (
wfServicer struct {
load func(ctx context.Context) error
exec func(ctx context.Context, workflowID uint64, p atypes.WorkflowExecParams) (*expr.Vars, uint64, atypes.Stacktrace, error)
load func(ctx context.Context) error
exec func(ctx context.Context, workflowID uint64, p atypes.WorkflowExecParams) (*expr.Vars, uint64, atypes.Stacktrace, error)
search func(ctx context.Context, filter atypes.WorkflowFilter) (atypes.WorkflowSet, atypes.WorkflowFilter, error)
}
)
@@ -228,6 +229,10 @@ func (f wfServicer) Exec(ctx context.Context, workflowID uint64, p atypes.Workfl
return f.exec(ctx, workflowID, p)
}
func (f wfServicer) Search(ctx context.Context, filter atypes.WorkflowFilter) (atypes.WorkflowSet, atypes.WorkflowFilter, error) {
return f.search(ctx, filter)
}
func must(v *expr.Vars, err error) *expr.Vars {
if err != nil {
return nil