Search workflow in processer via handle also
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user