Giter Club home page Giter Club logo

Comments (5)

timjonesdev avatar timjonesdev commented on June 16, 2024 2

I didn't see fallback specifically in the example, but cb.Execute returns a specific error immediately if the request is not going to be allowed (this is documented). It looks like you can check for gobreaker.ErrOpenState to trigger fallback logic. Something like:

mySuccessReturn, err := cb.Execute(func() (interface{}, error) {
    // do stuff
})
if err != nil {
    if errors.Is(err, gobreaker.ErrOpenState) {
        // circuit is open
        // this is where a fallback option happens
    } else { // this will be the returned error from "do stuff"
    }
}

from gobreaker.

YoshiyukiMineo avatar YoshiyukiMineo commented on June 16, 2024

Which fallback function are you referring to? Do you mean callback functions?

https://github.com/sony/gobreaker/blob/master/gobreaker.go#L106-L107

from gobreaker.

wjh000123 avatar wjh000123 commented on June 16, 2024

Hi, @YoshiyukiMineo ,
in hystrix pattern, an optional fallback function is used when the original func failed. Here's the wiki.

from gobreaker.

ahmedashraff avatar ahmedashraff commented on June 16, 2024

@timjonesdev what you suggested to implement the circuit breaker default fallback is good as it's true. However, if there's a default function passed with the setting struct it will be more easy to point, simple to change without touch the actual implementation, and descriptive for each service.

Its an opinion at the end.

from gobreaker.

1500mh avatar 1500mh commented on June 16, 2024

@ahmedashraff hello, i think we can customize trigger conditions by replacing cb.afterRequest(generation, err != nil) with cb.afterRequest(generation, cb.shouldChangeState(err)) like this:

type CircuitBreaker struct {
    ...
   shouldChangeState func(err error) bool
}

func defaultShouldChange(err error) bool {
    return err != nil
}

func (cb *CircuitBreaker) Execute(req func() (interface{}, error)) (interface{}, error) {
        ...
	result, err := req()
	cb.afterRequest(generation, cb.shouldChangeState(err))
	return result, err
}

from gobreaker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.