eventrules

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2018 License: Apache-2.0 Imports: 7 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChainIdentity

func ChainIdentity(ctx context.Context, e *scheduler.Event, err error) (context.Context, *scheduler.Event, 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

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 *scheduler.Event) []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

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

func Drop

func Drop() Rule

Drop aborts the Chain and returns the (context.Context, *scheduler.Event, 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 Handle

func Handle(h events.Handler) Rule

Handle generates a rule that executes the given events.Handler.

func HandleF

func HandleF(h events.HandlerFunc) Rule

HandleF is the functional equivalent of Handle

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) 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 *scheduler.Event, err error, ch Chain) (context.Context, *scheduler.Event, error)

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

func (Rule) Handle

func (r Rule) Handle(h events.Handler) Rule

Handle returns a Rule that invokes the receiver, then the given events.Handler

func (Rule) HandleEvent

func (r Rule) HandleEvent(ctx context.Context, e *scheduler.Event) (err error)

HandleEvent implements events.Handler for Rule

func (Rule) HandleF

func (r Rule) HandleF(h events.HandlerFunc) Rule

HandleF is the functional equivalent of Handle

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, *scheduler.Event, 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) Chain

func (rs Rules) Chain() Chain

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

func (Rules) Eval

func (rs Rules) Eval(ctx context.Context, e *scheduler.Event, err error, ch Chain) (context.Context, *scheduler.Event, 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.

func (Rules) HandleEvent

func (rs Rules) HandleEvent(ctx context.Context, e *scheduler.Event) error

HandleEvent implements events.Handler for Rules

Jump to

Keyboard shortcuts

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