-
-
Save ppaanngggg/5049a1845247aae21a6eb22681d7fad6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"github.com/cortezaproject/corteza-server/automation/service" | |
"github.com/cortezaproject/corteza-server/automation/types" | |
"github.com/cortezaproject/corteza-server/pkg/expr" | |
) | |
type workflowArgs struct { | |
Workflow uint64 | |
Input map[string]expr.TypedValue | |
} | |
func WorkflowHandler() *types.Function { | |
return &types.Function{ | |
Ref: "workflow", | |
Kind: "function", | |
Labels: map[string]string(nil), | |
Meta: &types.FunctionMeta{ | |
Short: "Call workflow", | |
}, | |
Parameters: []*types.Param{ | |
{ | |
Name: "workflow", | |
Types: []string{"UnsignedInteger"}, | |
Required: true, | |
Meta: &types.ParamMeta{Label: "workflow"}, | |
}, | |
{ | |
Name: "input", | |
Types: []string{"Vars"}, | |
}, | |
}, | |
Results: []*types.Param{ | |
{ | |
Name: "result", | |
Types: []string{"Vars"}, | |
}, | |
}, | |
Handler: func(ctx context.Context, in *expr.Vars) (*expr.Vars, error) { | |
args := &workflowArgs{} | |
if err := in.Decode(args); err != nil { | |
return nil, err | |
} | |
vars, err := expr.NewVars(args.Input) | |
if err != nil { | |
return nil, err | |
} | |
wp := types.WorkflowExecParams{ | |
Trace: true, Async: false, Wait: true, Input: vars, | |
} | |
result, _, err := service.DefaultWorkflow.Exec(ctx, args.Workflow, wp) | |
if err != nil { | |
return nil, err | |
} | |
out := &expr.Vars{} | |
tval, err := service.Registry().Type("Vars").Cast(result) | |
if err != nil { | |
return nil, err | |
} | |
if err := expr.Assign(out, "result", tval); err != nil { | |
return nil, err | |
} | |
return out, nil | |
}, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment