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

Dynamic halfOpenAfter for circuit breakers #68

Open
nth-commit opened this issue Sep 13, 2022 · 3 comments
Open

Dynamic halfOpenAfter for circuit breakers #68

nth-commit opened this issue Sep 13, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@nth-commit
Copy link

Is there any guidance around getting this to work?

I'm heavily hitting an API that I don't control, nor have much insight of their (seemingly inconsistent) rate-limiting functionality.

I would love it if I could do write a back-off function to workaround this, that grows with the number of attempts.

@connor4312
Copy link
Owner

You're asking how to get "[d]ynamic halfOpenAfter for circuit breakers" to work -- I'm not sure what you mean by this, can you elaborate?

@nth-commit
Copy link
Author

I want the circuit breaker timeout to be derived from number of attempts, rather than a constant value.

At the moment, this is my code:

const handleRateLimitations = handleWhen(isRateLimitationError)
const rateLimitationCircuitBreakerPolicy = circuitBreaker(handleRateLimitations, {
  breaker: new ConsecutiveBreaker(1),
  halfOpenAfter: 5 * 60 * 1_000,
})

Ideally, I want something like this:

const handleRateLimitations = handleWhen(isRateLimitationError)
const rateLimitationCircuitBreakerPolicy = circuitBreaker(handleRateLimitations, {
  breaker: new ConsecutiveBreaker(1),
  halfOpenAfter: new ExponentialBackoff({ maxDelay: 5 * 60 * 1000 }),
})

Where the attempt number that is passed to the backoff function is the number of consecutive times the circuit-breaker has gone from half-open (or closed) to open. The circuit breaker moving back to the closed state would reset the attempts to 0.

@connor4312
Copy link
Owner

I see. I think that makes sense. PR's welcome, or I will get to this at some point.

@connor4312 connor4312 added the enhancement New feature or request label Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants