Skip to content

Commit

Permalink
Fix for Sliding window breaker when values are updated dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
tichon29 committed Oct 26, 2020
1 parent 902f135 commit 70ce47b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
22 changes: 21 additions & 1 deletion docs/vue/components/module/SlidingWindowBreakerModule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,37 @@ export default {
.circle {
width: 20px;
height: 20px;
border-radius: 10px;
border-radius: 50%;
background: green;
margin-left: 5px;
margin-right: 5px;
// background-image: linear-gradient(to right, transparent 50%, currentColor 0);
// color: white
}
.circle.halfopened {
background: orange;
}
.circle.opened {
background: red;
}
// .circle::before {
// content: '';
// display: block;
// margin-left: 50%;
// height: 100%;
// border-radius: 0 100% 100% 0 / 50%;
// background-color: inherit;
// transform-origin: left;
// animation: spin 5s linear infinite, bg 10s step-end infinite;
// }
// @keyframes spin {
// to { transform: rotate(.5turn); }
// }
// @keyframes bg {
// 50% { background: currentColor; }
// }
}
}
</style>
2 changes: 1 addition & 1 deletion docs/vue/module/sliding/CountBreaker.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="mollitia-playground">
<Circuit ref="c1" :modules="modules" @end="onCircuitEnd">
<SlidingWindowBreakerModule slidingType="count" ref="cb1"></SlidingWindowBreakerModule>
<SlidingWindowBreakerModule name="toto" slidingType="count" ref="cb1"></SlidingWindowBreakerModule>
</Circuit>
</div>
</template>
Expand Down
7 changes: 3 additions & 4 deletions src/module/breaker/sliding/count-breaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ export class SlidingCountBreaker extends SlidingWindowBreaker<SlidingWindowReque
public async executeInClosed<T> (promise: any, ...params: any[]): Promise<T> {
const {requestResult, response } = await this.executePromise(promise, ...params);
this.callsInClosedState.push(requestResult);
let nbCalls = this.callsInClosedState.length;
const nbCalls = this.callsInClosedState.length;
if (nbCalls >= this.minimumNumberOfCalls) {
while (nbCalls > this.slidingWindowSize) {
this.callsInClosedState.shift();
nbCalls--;
if (nbCalls > this.slidingWindowSize) {
this.callsInClosedState.splice(0,(nbCalls - this.slidingWindowSize));
}
this.checkCallRatesClosed(this.open.bind(this));
}
Expand Down

0 comments on commit 70ce47b

Please sign in to comment.