Documentation ¶
Index ¶
- Constants
- Variables
- type Command
- func (c *Command) CacheKey() string
- func (c *Command) Fallback(ctx context.Context) (interface{}, error)
- func (c *Command) Group() string
- func (c *Command) IsCacheable() bool
- func (c *Command) Name() string
- func (c *Command) Properties(cfg vaquita.DynamicConfig) *CommandProperties
- func (c *Command) Run(ctx context.Context) (interface{}, error)
- type CommandBuilder
- type CommandExecutor
- type CommandFunc
- type CommandProperties
- type Executor
- type SemaphoreFactory
Constants ¶
const ( ExecutionTimeoutDefault = 0 ExecutionMaxConcurrentRequestsDefault = 100 FallbackEnabledDefault = true RequestCacheEnabledDefault = true RequestLogEnabledDefault = true CircuitBreakerEnabledDefault = true CircuitBreakerRequestVolumeThresholdDefault = 20 CircuitBreakerSleepWindowDefault = 5000 * time.Millisecond CircuitBreakerErrorThresholdPercentageDefault = 50 CircuitBreakerForceOpenDefault = false CircuitBreakerForceClosedDefault = false )
Variables ¶
var ( UnknownPanic = errors.New("unknown panic") SemaphoreRejected = errors.New("semaphore rejected") )
var FallbackNotImplemented = errors.New("Fallback not implemented")
FallbackNotImplemented is the error returned by Cimmand.Fallback when no fallback function is configured.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command is a wrapper for a code that requires latency and fault tolerance (typically service call over the network).
func (*Command) IsCacheable ¶
IsCacheable returns true id the response of the command execution can be cached.
func (*Command) Properties ¶
func (c *Command) Properties(cfg vaquita.DynamicConfig) *CommandProperties
type CommandBuilder ¶
type CommandBuilder struct {
// contains filtered or unexported fields
}
CommandBuilder is a helper used for constructing new Commands.
func NewCommand ¶
func NewCommand(name string, run CommandFunc) *CommandBuilder
NewCommand constructs a new CommandBuilder with minimal required command implementation (name and primary function).
func (*CommandBuilder) Build ¶
func (b *CommandBuilder) Build() *Command
Build builds a command with all configured parameters.
func (*CommandBuilder) CacheKey ¶
func (b *CommandBuilder) CacheKey(cacheKey string) *CommandBuilder
CacheKey sets a cache key to the command being build. This means that the command response can be cached and reused for the execution of the same command with the same key.
func (*CommandBuilder) Fallback ¶
func (b *CommandBuilder) Fallback(fallback CommandFunc) *CommandBuilder
Fallback adds a fallback function to the command being built.
func (*CommandBuilder) Group ¶
func (b *CommandBuilder) Group(name string) *CommandBuilder
Group sets a group name for a command. The default group name is the name of the command. Group name is used for limiting the concurrent execution of the command for the entire group.
type CommandExecutor ¶
type CommandExecutor struct {
// contains filtered or unexported fields
}
CommandExecutor is an implementation of an Executor interface.
func NewExecutor ¶
func NewExecutor(cfg vaquita.DynamicConfig) *CommandExecutor
NewExecutor constructs a new empty executor.
func NewExecutorWithClock ¶
func NewExecutorWithClock(cfg vaquita.DynamicConfig, clock util.Clock) *CommandExecutor
func (*CommandExecutor) Exec ¶
func (e *CommandExecutor) Exec(ctx context.Context, cmd *Command) (result interface{}, err error)
Exec executes a command and handles command execution errors. If command fails with an error or panics Fallback function with fallback logic is executed. Every command execution is guarded by an internal circuit-breaker. Panics are recovered and returned as errors.
func (*CommandExecutor) IsCircuitBreakerOpen ¶
func (e *CommandExecutor) IsCircuitBreakerOpen(cmdName string) bool
func (*CommandExecutor) Metrics ¶
func (e *CommandExecutor) Metrics() *metrics.ExecutionMetrics
type CommandFunc ¶
A CommandFunc is a function that contains the primary or fallback logic for the command.
type CommandProperties ¶
type CommandProperties struct { ExecutionTimeout vaquita.DurationProperty ExecutionMaxConcurrentRequests vaquita.IntProperty FallbackEnabled vaquita.BoolProperty RequestCacheEnabled vaquita.BoolProperty RequestLogEnabled vaquita.BoolProperty CircuitBreaker *circuitbreaker.CircuitBreakerProperties }
func GetProperties ¶
func GetProperties(cfg vaquita.DynamicConfig, commandName, commandGroup string) *CommandProperties
type Executor ¶
Executor is a main service that knows how to execute commands and handle their errors. Executor must be safe to be accessed by multiple goroutines.
type SemaphoreFactory ¶
type SemaphoreFactory struct {
// contains filtered or unexported fields
}
func NewSemaphoreFactory ¶
func NewSemaphoreFactory() *SemaphoreFactory
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Port of Hystrix usage example from: https://github.com/Netflix/Hystrix/blob/master/hystrix-examples/src/main/java/com/netflix/hystrix/examples/demo/HystrixCommandDemo.java
|
Port of Hystrix usage example from: https://github.com/Netflix/Hystrix/blob/master/hystrix-examples/src/main/java/com/netflix/hystrix/examples/demo/HystrixCommandDemo.java |