-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Don't use Status for managing breaker state
The `Status` object is really only for keeping track of various events that occur within the breaker. The CircuitBreaker doesn't really need to manage those counts. And it especially doesn't need to depend on them for managing state. Move `Status` to its own module, and have it use breaker events to manage its own stats.
- Loading branch information
Showing
3 changed files
with
35 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const CIRCUIT_BREAKER = Symbol('circuit-breaker'); | ||
|
||
class Status { | ||
constructor (circuit) { | ||
this.failures = 0; | ||
this.fallbacks = 0; | ||
this.successes = 0; | ||
this.rejects = 0; | ||
this.fires = 0; | ||
this[CIRCUIT_BREAKER] = circuit; | ||
circuit.on('success', () => this.successes++); | ||
circuit.on('failure', () => this.failures++); | ||
circuit.on('fallback', () => this.fallbacks++); | ||
circuit.on('fire', () => this.fires++); | ||
circuit.on('reject', () => this.rejects++); | ||
} | ||
} | ||
|
||
module.exports = exports = Status; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters