when

package
v0.35.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2021 License: GPL-2.0, GPL-3.0 Imports: 6 Imported by: 0

README

when - Conditional Executor

The when middleware makes the execution of a pipe dependent on the evaluation of a boolean expression.

Arguments

It takes a single string argument that should evaluate to a boolean expression. Please refer to the GoValuate documentation for a list of supported operators and types.

Since pipedream uses GoValuate under the hood, it makes no distinction between single and double quotes in boolean expressions (see this issue).

private:
    some-pipe:
        # this pipe will not be executed
        arg: fail
        when: "@{arg} == 'success'"

        # this pipe will be executed
        arg: successful
        # regexes can be used for matching
        when: "@{arg} =~ 'success'"

Note that the behavior of when in child pipes can be a little confusing when argument interpolation is used. Interpolation of the child's invocation arguments takes place at parent invocation time, so values passed to the child might be ignored.

private:
    parent-pipe:
        arg: fail
        pipe:
            - child-pipe:
                arg: success
                # this pipe will not be executed, because the argument is interpolated at parent invocation time
                # using the parent's argument value "fail"
                when: "@{arg} == 'success'"
            - another-child-pipe:
                arg: success

    another-child-pipe:
        # this pipe will be executed, because the argument is interpolated at child invocation time
        # using the child's argument value "success"
        when: "@{arg} == 'success'"

Documentation

Overview

Package when provides a middleware that enables conditional execution

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware added in v0.32.2

type Middleware struct {
}

Middleware is a conditional executor

func NewMiddleware added in v0.32.2

func NewMiddleware() Middleware

NewMiddleware creates a new middleware instance

func (Middleware) Apply added in v0.32.2

func (whenMiddleware Middleware) Apply(
	run *pipeline.Run,
	next func(*pipeline.Run),
	executionContext *middleware.ExecutionContext,
)

Apply is where the middleware's logic resides

It adapts the run based on its slice of the run's arguments. It may also trigger side effects such as executing shell commands or full runs of other pipelines. When done, this function should call next in order to continue unwinding the stack.

func (Middleware) String added in v0.32.2

func (whenMiddleware Middleware) String() string

String is a human-readable description

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL