awolden / brakes

Hystrix compliant Node.js Circuit Breaker Library
MIT License
300 stars 35 forks source link

What happen when the circuit is opened? #71

Closed mazzy89 closed 7 years ago

mazzy89 commented 7 years ago

Probably it is my lack in understanding the circuit brake pattern, but let's take examples/healthCheck-example.js. What happen when the circuit is opened?

awolden commented 7 years ago

@mazzy89 Thanks for the question!

When a circuit is opened, it will stop sending requests downstream to the main function you passed in when creating a circuit breaker. The brakes instance will instantly fail and pass back a CircuitBrokenError. Based on how you have configured the circuit, this will happen for set period of time or until a healthCheck returns true.

In the health check example, there is a service that will fail as time goes on (unreliableServiceCall) so after a certain amount of attempts the circuit will open. The circuit in that example is configured with a healthCheck, so the circuit won't open again until the function/promise passed in as a health check resolves true.