Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added predicate fn to switch "Half Open" to "Open" #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Sandy10247
Copy link

Description

  • Added predicate Fn "ReadyToOpen" for Settings and consumed it in CircuitBreaker initalization.
  • Added defaultReadyToOpen fn implemetation, when parent won't provide one, this will be used as default behaviout.

usage

cfg := gobreaker.Settings{
		// When to flush counters int the Closed state
		Interval: 5 * time.Second,
		// Time to switch from Open to Half-open
		Timeout: 7 * time.Second,
		// Function with check when to switch from Closed to Open
		ReadyToTrip: shouldBeSwitchedToOpen,
		// set Max Request in Half Open state to 5
		MaxRequests: 5,
		// On State change Handler Fn
		OnStateChange: func(_ string, from gobreaker.State, to gobreaker.State) {
			// Handler for every state change. We'll use for debugging purpose
			logger.Println("state changed from", from.String(), "to", to.String())
		},
		ReadyToOpen: func(counts gobreaker.Counts) bool {
			fmt.Printf("Ready to open called\n")
			return true
		},
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants