Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement dynamic behavior for halfOpenAfter #96

Closed
wants to merge 1 commit into from

Conversation

ghost91-
Copy link
Contributor

Closes #68

@ghost91-
Copy link
Contributor Author

ghost91- commented Jul 19, 2024

I haven't added anything to the readme because I didn't really see a proper place for documenting the new behavior of halfOpenAfter. So far, halfOpenAfter is not described explicitly at all in the readme. If you want me to add some documentation about it, please let me know where in the documentation you think it fits best.

@ghost91- ghost91- force-pushed the dynamic-half-open-after branch 3 times, most recently from 701daae to 23981f6 Compare July 19, 2024 22:27
@ghost91- ghost91- force-pushed the dynamic-half-open-after branch from 23981f6 to 3f79ed6 Compare July 19, 2024 22:32
@@ -167,7 +198,7 @@ export class CircuitBreakerPolicy implements IPolicy {
return this.execute(fn);

case CircuitState.Open:
if (Date.now() - state.openedAt < this.options.halfOpenAfter) {
if (Date.now() - state.openedAt < (this.halfOpenAfterBackof?.duration ?? 0)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The halfOpenAfterBackoff should be stored in the state to avoid the null assertion (which should never happen)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I didn't think of that.

@connor4312
Copy link
Owner

Merged in 99e5887

@connor4312 connor4312 closed this Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic halfOpenAfter for circuit breakers
2 participants