Documentation
¶
Index ¶
Constants ¶
const ( Compose = "compose" ComposeInput = types.InputMain )
const ( Fail = "fail" FailInputMsg = types.InputMain )
const ( Foreach = "foreach" ForeachInputForeach = "foreach" ForeachInputDo = "do" ForeachInputCollect = "collect" ForeachInputSequential = "sequential" )
const ( Http = "http" HttpInputUrl = "url" )
const ( If = "if" IfInputCondition = "if" IfInputThen = "then" IfInputElse = "else" )
const ( Javascript = "javascript" JavascriptInputExpr = "expr" JavascriptInputArgs = "args" )
const ( Noop = "noop" NoopInput = types.InputMain )
const ( Repeat = "repeat" RepeatInputTimes = "times" RepeatInputDo = "do" RepeatInputPrev = "_prev" )
const ( Sleep = "sleep" SleepInput = types.InputMain SleepInputDefault = time.Duration(1) * time.Second )
const ( Switch = "switch" SwitchInputCondition = "switch" // required SwitchInputCases = "cases" // optional SwitchInputDefaultCase = "default" // optional SwitchCaseKey = "case" SwitchCaseValue = "action" )
const ( While = "while" WhileInputExpr = "expr" WhileInputLimit = "limit" WhileInputDelay = "delay" WhileInputAction = "do" )
Variables ¶
var DefaultBuiltinFunctions = map[string]native.InternalFunction{ If: &FunctionIf{}, Noop: &FunctionNoop{}, "nop": &FunctionNoop{}, Compose: &FunctionCompose{}, Sleep: &FunctionSleep{}, Repeat: &FunctionRepeat{}, Javascript: NewFunctionJavascript(), Fail: &FunctionFail{}, Http: NewFunctionHTTP(), Foreach: &FunctionForeach{}, Switch: &FunctionSwitch{}, While: &FunctionWhile{}, }
var (
ErrLimitExceeded = errors.New("while limit exceeded")
)
Functions ¶
This section is empty.
Types ¶
type FunctionCompose ¶
type FunctionCompose struct{}
FunctionCompose provides a way to merge, modify and create complex values from multiple inputs. Other than outputting the composed inputs, compose does not perform any other operation. This is useful when you want to merge the outputs from different tasks (for example in a MapReduce or scatter-gather scenario).
**Specification**
**input** | required | types | description ------------|----------|--------|--------------------------------- default | no | * | the inputs to be merged into a single map or outputted if none other. * | no | * | the inputs to be merged into a single map.
**Note: custom message does not yet propagate back to the user**
**output** (*) The composed map, single default input, or nothing.
**Example**
Compose with a single input, similar to `noop`: ```yaml # ... foo:
run: compose inputs: "all has failed"
# ... ```
Composing a map inputs: ```yaml # ... foo:
run: compose inputs: foo: bar fission: workflows
# ... ```
TODO avoid adding function-injected fields to compose
func (*FunctionCompose) Invoke ¶
func (fn *FunctionCompose) Invoke(spec *types.TaskInvocationSpec) (*typedvalues.TypedValue, error)
type FunctionFail ¶
type FunctionFail struct{}
FunctionFail is a function that always fails. This can be used to short-circuit workflows in specific branches. Optionally you can provide a custom message to the failure.
**Specification**
**input** | required | types | description ------------|----------|--------|--------------------------------- default | no | string | custom message to show on error
**output** None
**Example**
```yaml # ... foo:
run: fail inputs: "all has failed"
# ... ```
A runnable example of this function can be found in the [failwhale](../examples/whales/failwhale.wf.yaml) example.
func (*FunctionFail) Invoke ¶
func (fn *FunctionFail) Invoke(spec *types.TaskInvocationSpec) (*typedvalues.TypedValue, error)
type FunctionForeach ¶
type FunctionForeach struct{}
FunctionForeach is a control flow construct to execute a certain task for each item in the provided input. The tasks are executed in parallel. Note, currently the task in the 'do' does not have access to state in the current workflow.
**Specification**
**input** | required | types | description -------------------------|----------|---------------|-------------------------------------------------------- foreach | yes | list | The list of elements that foreach should be looped over. do | yes | task/workflow | The action to perform for every element. sequential | no | bool | Whether to execute the tasks sequentially (default: false). collect | no | bool | Collect the outputs of the tasks into an array (default: true).
The element is made available to the action using the field `_item`.
**output** None
**Example**
``` foo:
run: foreach inputs: for: - a - b - c do: run: noop inputs: "{ task().Inputs._item }"
```
A complete example of this function can be found in the [foreachwhale](../examples/whales/foreachwhale.wf.yaml) example.
func (*FunctionForeach) Invoke ¶
func (fn *FunctionForeach) Invoke(spec *types.TaskInvocationSpec) (*typedvalues.TypedValue, error)
type FunctionHTTP ¶
type FunctionHTTP struct {
// contains filtered or unexported fields
}
HttpFunction is a general utility function to perform simple HTTP requests. It is useful for prototyping and managing low overhead HTTP requests. To this end it offers basic functionality, such as setting headers, query, method, url, and body inputs.
**Specification**
**input** | required | types | description ----------------|----------|-------------------|-------------------------------------------------------- url/default | yes | string | URL of the request. headers | no | map[string|string | The action to perform for every element. content-type | no | string | Force a specific content-type for the request. method | no | string | HTTP Method of the request. (default: GET) body | no | * | The body of the request. (default: application/octet-stream)
Unless the content type is specified explicitly, the workflow engine will infer the content-type based on the body.
**output** (*) the body of the response.
Note: currently you cannot access the metadata of the response.
**Example**
```yaml # ... httpExample:
run: http inputs: url: http://fission.io method: post body: "foo"
# ... ```
A complete example of this function can be found in the [httpwhale](../examples/whales/httpwhale.wf.yaml) example.
func NewFunctionHTTP ¶
func NewFunctionHTTP() *FunctionHTTP
func (*FunctionHTTP) Invoke ¶
func (fn *FunctionHTTP) Invoke(spec *types.TaskInvocationSpec) (*typedvalues.TypedValue, error)
type FunctionIf ¶
type FunctionIf struct{}
FunctionIf is the simplest ways of altering the control flow of a workflow. It allows you to implement an if-else construct; executing a branch or returning a specific output based on the result of an execution.
**Specification**
**input** | required | types | description ----------------|----------|-------------------|-------------------------------------------------------- if | yes | bool | The condition to evaluate. then | no | * | Value or action to return if the condition is true. else | no | * | Value or action to return if the condition is false.
Unless the content type is specified explicitly, the workflow engine will infer the content-type based on the body.
**output** (*) Either the input of `then` or `else` (or none if not set).
**Example**
The following example shows the dynamic nature of this control flow. If the if-expression evaluates to true, a static value is outputted. Otherwise, a function is outputted (which in turn is executed).
```yaml # ... ifExample:
run: if inputs: if: { param() > 42 } then: "foo" else: run: noop
# ... ```
A complete example of this function can be found in the [maybewhale](../examples/whales/maybewhale.wf.yaml) example.
func (*FunctionIf) Invoke ¶
func (fn *FunctionIf) Invoke(spec *types.TaskInvocationSpec) (*typedvalues.TypedValue, error)
type FunctionJavascript ¶
type FunctionJavascript struct {
// contains filtered or unexported fields
}
FunctionJavascript allows you to create a task that evaluates an arbitrary JavaScript expression. The implementation is similar to the inline evaluation of JavaScript in [expressions](./expressions.md) in inputs. In that sense this implementations does not offer more functionality than inline expressions. However, as it allows you to implement the entire task in JavaScript, this function is useful for prototyping and stubbing particular functions.
**Specification**
**input** | required | types | description ----------------|----------|-------------------|-------------------------------------------------------- expr | yes | string | The JavaScript expression args | no | * | The arguments that need to be present in the expression.
Note: the `expr` is of type `string` - not a `expression` - to prevent the workflow engine from evaluating the expression prematurely.
**output** (*) The output of the expression.
**Example**
```yaml # ... JsExample:
run: javascript inputs: expr: "a ^ b" args: a: 42 b: 10
# ... ```
A complete example of this function can be found in the [fibonacci](../examples/misc/fibonacci.wf.yaml) example.
func NewFunctionJavascript ¶
func NewFunctionJavascript() *FunctionJavascript
func (*FunctionJavascript) Invoke ¶
func (fn *FunctionJavascript) Invoke(spec *types.TaskInvocationSpec) (*typedvalues.TypedValue, error)
type FunctionNoop ¶
type FunctionNoop struct{}
FunctionNoop represents a "no operation" task; it does not do anything. The input it receives in its default key, will be outputted in the output
**Specification**
**input** | required | types | description ----------------|----------|-------------------|-------------------------------------------------------- default | no | * | The input to pass to the output.
**output** (*) The output of the default input if provided.
**Example**
```yaml # ... NoopExample:
run: noop inputs: foobar
# ... ```
A complete example of this function can be found in the [fortunewhale](../examples/whales/fortunewhale.wf.yaml) example.
func (*FunctionNoop) Invoke ¶
func (fn *FunctionNoop) Invoke(spec *types.TaskInvocationSpec) (*typedvalues.TypedValue, error)
type FunctionRepeat ¶
type FunctionRepeat struct{}
FunctionRepeat, as the name suggests, repeatedly executes a specific function. The repeating is based on a static number, and is done sequentially. The subsequent tasks can access the output of the previous task with `prev`.
**Specification**
**input** | required | types | description ----------------|----------|-------------------|-------------------------------------------------------- times | yes | number | Number of times to repeat the task. do | yes | task | The task to execute.
Note: the task `do` gets the output of the previous task injected into `prev`.
**output** (*) The output of the last task.
**Example**
```yaml # ... RepeatExample:
run: repeat inputs: times: 5 do: run: noop inputs: { task().prev + 1 }}
# ... ```
A complete example of this function can be found in the [repeatwhale](../examples/whales/repeatwhale.wf.yaml) example.
TODO minor: chose between unrolled loop and dynamic loop based on number of tasks for performance
func (*FunctionRepeat) Invoke ¶
func (fn *FunctionRepeat) Invoke(spec *types.TaskInvocationSpec) (*typedvalues.TypedValue, error)
type FunctionSleep ¶
type FunctionSleep struct{}
FunctionSleep is similarly to `noop` a "no operation" function. However, the `sleep` function will wait for a specific amount of time before "completing". This can be useful to mock or stub out functions during development, while simulating the realistic execution time.
**Specification**
**input** | required | types | description ----------------|----------|-------------------|-------------------------------------------------------- default | no | string | A string-based representation of the duration of the sleep. (default: 1 second)
Note: the sleep input is parsed based on the [Golang Duration string notation](https://golang.org/pkg/time/#ParseDuration). Examples: 1 hour and 10 minutes: `1h10m`, 2 minutes and 300 milliseconds: `2m300ms`.
**output** None
**Example**
```yaml # ... NoopExample:
run: sleep inputs: 1h
# ... ```
A complete example of this function can be found in the [sleepalot](../examples/misc/sleepalot.wf.yaml) example.
func (*FunctionSleep) Invoke ¶
func (f *FunctionSleep) Invoke(spec *types.TaskInvocationSpec) (*typedvalues.TypedValue, error)
type FunctionSwitch ¶
type FunctionSwitch struct{}
Switch is very similar to how switch-constructs are implemented in most languages. In this case the switch is limited to evaluating string keys. The string-switch is matched to one of the cases, or - if none of those match - the default case.
**Specification**
**input** | required | types | description ----------------|----------|-------------------|-------------------------------------------------------- switch | yes | string | The string to match to one of the cases. cases | no | list | List of cases to match to. default | no | * | The default value if there is no matching case.
**output** (*) Either the value of the matching case, the default, or nothing (in case the default is not specified).
**Example**
```yaml # ... SwitchExample:
run: switch inputs: switch: "{ param() }" cases: - case: foo action: bar - case: ac action: me default: 42
# ... ```
A complete example of this function can be found in the [switchwhale](../examples/whales/switchwhale.wf.yaml) example.
func (*FunctionSwitch) Invoke ¶
func (fn *FunctionSwitch) Invoke(spec *types.TaskInvocationSpec) (*typedvalues.TypedValue, error)
type FunctionWhile ¶
type FunctionWhile struct{}
FunctionWhile consists of a control flow construct that will execute a specific task as long as the condition has not been met. The results of the executed action can be accessed using the task id "action".
**Specification**
**input** | required | types | description ----------------|----------|-------------------|-------------------------------------------------------- expr | yes | bool | The condition which determines whether to continue or halt the loop. do | yes | task/workflow | The action to execute on each iteration. limit | yes | number | The max number of iterations of the loop.
Notes: - we currently cannot reevaluate the expr. There needs to be support for looking up the source of an expression. Maybe we can add the original expression to the labels. - we might want to have a `prev` value here to reference the output of the previous iteration.
**output** (*) Either the value of the matching case, the default, or nothing (in case the default is not specified).
**Example**
```yaml # ... SwitchExample:
run: while inputs: expr: "{ 42 > 0 }" limit: 10 do: run: noop
# ... ```
A complete example of this function can be found in the [whilewhale](../examples/whales/whilewhale.wf.yaml) example.
func (*FunctionWhile) Invoke ¶
func (fn *FunctionWhile) Invoke(spec *types.TaskInvocationSpec) (*typedvalues.TypedValue, error)