Skip to content

Instantly share code, notes, and snippets.

@ganny26
Created June 8, 2022 07:36
Show Gist options
  • Save ganny26/df1c4c5149d7f3b95ec669c62336afd3 to your computer and use it in GitHub Desktop.
Save ganny26/df1c4c5149d7f3b95ec669c62336afd3 to your computer and use it in GitHub Desktop.
circuit
const config = {
name: 'appCounter',
slidingWindowSize: 6, // Failure Rate Calculation is done on the last 6 iterations
minimumNumberOfCalls: 3, // 3 iterations are needed to start calculating the failure rate, and see if circuit should be opened or not
failureRateThreshold: 60, // If half of the iterations or more are failing, the circuit is switched to Opened state.
slowCallDurationThreshold: 500, // An iteration is considered as being slow if the iteration lasts more than 1s
slowCallRateThreshold: 50, // If at least 80% of the iterations are considered as being slow, the circuit is switched to Opened state.
permittedNumberOfCallsInHalfOpenState: 2, // When the circuit is in Half Opened state, the circuit accepts 2 iterations in this state.
openStateDelay: 10000, // The circuit stays in Opened state for 10s
halfOpenStateMaxDelay: 30000,
}
// Sliding counter
const slidingCountBreaker = new SlidingCountBreaker(config)
// Create fallback
const fallback = new Fallback({
callback(err) {
// Every time the method rejects, You can filter here
if (err) {
return err.message
}
},
})
// Creates a circuit
const orderCircuit = new Circuit({
name: 'Order Operations',
options: {
prometheus: {
name: 'orderCircuit',
},
modules: [slidingCountBreaker, fallback],
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment