Skip to content

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