concurrencylimit

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2019 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FailureOnExternalErrorPolicy = func(_ context.Context, err error) limit.Result {

	if err == nil {
		return limit.ResultSuccess
	}

	if err != nil && err != errors.ErrRejectedExecution {
		return limit.ResultFailure
	}

	return limit.ResultIgnore
}

FailureOnExternalErrorPolicy will treat as failure every error that is not from concurrencylimit package (this is the error by the limiters).

View Source
var FailureOnRejectedPolicy = func(_ context.Context, err error) limit.Result {

	if err == nil {
		return limit.ResultSuccess
	}

	if err != nil && err == errors.ErrRejectedExecution {
		return limit.ResultFailure
	}

	return limit.ResultIgnore
}

FailureOnRejectedPolicy will treat as failure every time the execution has been rejected with a `errors.ErrRejectedExecution` error.

View Source
var NoFailurePolicy = func(_ context.Context, err error) limit.Result {

	if err == nil {
		return limit.ResultSuccess
	}

	return limit.ResultIgnore
}

NoFailurePolicy will treat will never return a failure, just ignore when an error occurs, this can be used to adapt only on RTT/latency.

Functions

func New

func New(cfg Config) goresilience.Runner

New returns a new goresilience concurrency limit Runner.

func NewMiddleware

func NewMiddleware(cfg Config) goresilience.Middleware

NewMiddleware returns a new concurrent limit middleware

Types

type Config

type Config struct {
	// Limiter is the algorithm implementation that will calculate
	// the limits in adaptive way.
	Limiter limit.Limiter
	// Executor is the implementation used to execute the functions internally. It maintains
	// the workers dynamically based on the CongestionControlAlgorithm limits.
	Executor execute.Executor
	// ExecutionResultPolicy is a function where the execution error will be passed along with
	// the context and return if that result should be treated as a success, an error or ignored
	// by the concurrency control algorithm.
	// By default every error will count as an error.
	ExecutionResultPolicy ExecutionResultPolicy
}

Config is the concurrency limit algorithm

type ExecutionResultPolicy

type ExecutionResultPolicy func(ctx context.Context, err error) limit.Result

ExecutionResultPolicy is the function that will have the responsibility of categorizing the result of the execution for the limiter algorithm. For example depending on the type of the execution a connection error could be treated like an failure in the algorithm or just ignore it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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