callrules

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChainIdentity

func ChainIdentity(ctx context.Context, e *executor.Call, z mesos.Response, err error) (context.Context, *executor.Call, mesos.Response, error)

ChainIdentity is a Chain that returns the arguments as its results.

func Error

func Error(es ...error) error

Error aggregates, and then flattens, a list of errors accrued during rule processing. Returns nil if the given list of errors is empty or contains all nil errors.

func Error2

func Error2(a, b error) error

Error2 aggregates the given error params, returning nil if both are nil. Use Error2 to avoid the overhead of creating a slice when aggregating only 2 errors.

func IsErrorList

func IsErrorList(err error) bool

IsErrorList returns true if err is a non-nil error list

Types

type Chain

type Chain func(context.Context, *executor.Call, mesos.Response, error) (context.Context, *executor.Call, mesos.Response, error)

Chain is invoked by a Rule to continue processing an event. If the chain is not invoked, no additional rules are processed.

type ErrorList

type ErrorList []error

ErrorList accumulates errors that occur while processing a Chain of Rules. Accumulated errors should be appended to the end of the list. An error list should never be empty. Callers should use the package Error() func to properly accumulate (and flatten) errors.

func (ErrorList) Err

func (es ErrorList) Err() error

Err reduces an empty or singleton error list

func (ErrorList) Error

func (es ErrorList) Error() string

Error implements error; returns the message of the first error in the list.

type Labeler

type Labeler func(ctx context.Context, e *executor.Call) []string

Labeler generates a set of strings that should be associated with metrics that are generated for the given event.

type Overflow

type Overflow int
const (
	// OverflowWait waits until the rule may execute, or the context is canceled.
	OverflowWait Overflow = iota
	// OverflowOtherwise skips over the decorated rule and invoke an alternative instead.
	OverflowOtherwise
)

type Rule

type Rule func(context.Context, *executor.Call, mesos.Response, error, Chain) (context.Context, *executor.Call, mesos.Response, error)

Rule is the functional adaptation of evaler. A nil Rule is valid: it is Eval'd as a noop.

func Call

func Call(caller calls.Caller) Rule

Call returns a Rule that invokes the given Caller

func CallF

func CallF(cf calls.CallerFunc) Rule

CallF returns a Rule that invokes the given CallerFunc

func Drop

func Drop() Rule

Drop aborts the Chain and returns the (context.Context, *executor.Call, error) tuple as-is.

func DropOnError

func DropOnError() Rule

DropOnError returns a Rule that generates a nil event if the error state != nil

func DropOnSuccess

func DropOnSuccess() Rule

func Fail

func Fail(injected error) Rule

Fail returns a Rule that injects the given error.

func Metrics

func Metrics(harness metrics.Harness, labeler Labeler) Rule

Metrics generates a Rule that invokes the given harness for each event, using the labels generated by the Labeler. Panics if harness or labeler is nil.

func New

func New(rs ...Rule) Rule

New is the semantic equivalent of Rules{r1, r2, ..., rn}.Eval and exists purely for convenience.

func (Rule) AndThen

func (r Rule) AndThen(next ...Rule) Rule

AndThen returns a list of rules, beginning with the receiver, followed by DropOnError, and then all of the rules specified by the next parameter. The net effect is: execute the receiver rule and only if there is no error state, continue processing the next rules, in order.

func (Rule) Call

func (r Rule) Call(ctx context.Context, c *executor.Call) (mesos.Response, error)

Call implements the Caller interface for Rule

func (Rule) Caller

func (r Rule) Caller(caller calls.Caller) Rule

Caller returns a Rule that invokes the receiver and then calls the given Caller

func (Rule) CallerF

func (r Rule) CallerF(cf calls.CallerFunc) Rule

CallerF returns a Rule that invokes the receiver and then calls the given CallerFunc

func (Rule) DropOnError

func (r Rule) DropOnError() Rule

DropOnError decorates a rule by pre-checking the error state: if the error state != nil then the receiver is not invoked and (e, err) is returned; otherwise control passes to the receiving rule.

func (Rule) DropOnSuccess

func (r Rule) DropOnSuccess() Rule

func (Rule) Eval

func (r Rule) Eval(ctx context.Context, e *executor.Call, z mesos.Response, err error, ch Chain) (context.Context, *executor.Call, mesos.Response, error)

Eval is a convenience func that processes a nil Rule as a noop.

func (Rule) If

func (r Rule) If(b bool) Rule

If only executes the receiving rule if b is true; otherwise, the returned rule is a noop.

func (Rule) OnFailure

func (r Rule) OnFailure(next ...Rule) Rule

func (Rule) Once

func (r Rule) Once() Rule

Once returns a Rule that executes the receiver only once.

func (Rule) RateLimit

func (r Rule) RateLimit(p <-chan struct{}, over Overflow, otherwise Rule) Rule

RateLimit invokes the receiving Rule if a read of chan "p" succeeds (closed chan = no rate limit), otherwise proceeds according to the specified Overflow policy. May be useful, for example, when rate-limiting logged events. Returns nil (noop) if the receiver is nil, otherwise a nil chan will normally trigger an overflow. Panics when OverflowWait is specified with a nil chan, in order to prevent deadlock. A cancelled context will trigger the "otherwise" rule.

func (Rule) ThenDrop

func (r Rule) ThenDrop() Rule

ThenDrop executes the receiving rule, but aborts the Chain, and returns the (context.Context, *executor.Call, mesos.Response, error) tuple as-is.

func (Rule) Unless

func (r Rule) Unless(b bool) Rule

Unless only executes the receiving rule if b is false; otherwise, the returned rule is a noop.

func (Rule) UnlessDone

func (r Rule) UnlessDone() Rule

UnlessDone returns a decorated rule that checks context.Done: if the context has been canceled then the rule chain is aborted and the context.Err is merged with the current error state. Returns nil (noop) if the receiving Rule is nil.

type Rules

type Rules []Rule

Rules is a list of rules to be processed, in order.

func (Rules) Call

func (rs Rules) Call(ctx context.Context, c *executor.Call) (mesos.Response, error)

Call implements the Caller interface for Rules

func (Rules) Chain

func (rs Rules) Chain() Chain

Chain returns a Chain that evaluates the given Rules, in order, propagating the (context.Context, *executor.Call, error) from Rule to Rule. Chain is safe to invoke concurrently.

func (Rules) Eval

func (rs Rules) Eval(ctx context.Context, e *executor.Call, z mesos.Response, err error, ch Chain) (context.Context, *executor.Call, mesos.Response, error)

Eval is a Rule func that processes the set of all Rules. If there are no rules in the set then control is simply passed to the Chain.

Jump to

Keyboard shortcuts

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