cbreak

package module
v0.0.0-...-cc893f5 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 5 Imported by: 0

README

cbreak

Package implementing circuitbreaker

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrCircuitOpen is returned on function calls during Open Circuit State
	ErrCircuitOpen = errors.New("circuit open")
)

Functions

This section is empty.

Types

type Action

type Action func() (interface{}, error)

Action is the signature used inside Execute function that runs the circuitBreaker.

type CircuitBreaker

type CircuitBreaker struct {
	// contains filtered or unexported fields
}

CircuitBreaker is the main struct of the project

func New

New initiate a new CircuitBreaker Object.

func (*CircuitBreaker) Execute

func (cb *CircuitBreaker) Execute(ctx context.Context, fn Action) (interface{}, error)

Execute executes the user defined function in the circuit breaker

func (*CircuitBreaker) GetState

func (cb *CircuitBreaker) GetState() State

GetState returns current state of the circuit breaker. 0 -> Open, 1 -> Half, 2 -> Closed

type CircuitBreakerOpts

type CircuitBreakerOpts struct {
	// Number of errors past which the circuit breaker will open
	Threshold uint

	//
	// value from 1 to 99. When HsThresholdPercentage of good requests is reached in half state , circuit is closed
	// any input below 1 will be set to 1 and value above 99 will be set to 99
	HsThresholdPercentage uint

	// Function passed with this signature will be called whenever a state is changed.
	NotifyFunc func(s int)

	//Sleep time after which OpenCircuit switches to Half-Open.
	Duration time.Duration
}

CircuitBreakerOpts is the option Configuration struct

type State

type State byte

State type which tells which state the circuitbreaker is int

const (
	//Open State
	Open State = iota
	//Half Open State
	Half
	//Closed State
	Closed
)

Jump to

Keyboard shortcuts

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