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

circuitBreaker .d.ts example doesn't provide a halfOpenAfter and would result in a TS error #24

Closed
Tyriar opened this issue Jun 23, 2020 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@Tyriar
Copy link

Tyriar commented Jun 23, 2020

From .d.ts:

     * // Break if more than 20% of requests fail in a 30 second time window:
     * const breaker = Policy
     *  .handleAll()
     *  .circuitBreaker(new SamplingBreaker(0.2, 30 * 1000));
     *
     * export function handleRequest() {
     *   return breaker.execute(() => getInfoFromDatabase());
     * }
     * ```
     *
     * @param breaker -- The circuit breaker to use. This package exports
     * ConsecutiveBreaker and SamplingBreakers for you to use.
     * @param halfOpenAfter -- Time after failures to try to open the circuit
     * breaker again. Defaults to 10 seconds.
     */
    circuitBreaker(halfOpenAfter: number, breaker: IBreaker): CircuitBreakerPolicy;

image

@connor4312 connor4312 added the documentation Improvements or additions to documentation label Jun 23, 2020
@Tyriar
Copy link
Author

Tyriar commented Jun 23, 2020

"Defaults to 10 seconds." is still there, does that mean is 0 is passed in for halfOpenAfter?

@connor4312
Copy link
Owner

connor4312 commented Jun 23, 2020

There is no default, halfOpenAfter must be manually specified. Fixed that in the docs. I realized as a library I didn't know enough about the underlying service to determine an appropriate interval.

Updated docs:

cockatiel/src/Policy.ts

Lines 392 to 423 in d7b1d4f

/**
* Returns a circuit breaker for the policy. **Important**: you should share
* your circuit breaker between executions of whatever function you're
* wrapping for it to function!
*
* ```ts
* import { SamplingBreaker, Policy } from 'cockatiel';
*
* // Break if more than 20% of requests fail in a 30 second time window:
* const breaker = Policy
* .handleAll()
* .circuitBreaker(10_000, new SamplingBreaker(0.2, 30 * 1000));
*
* export function handleRequest() {
* return breaker.execute(() => getInfoFromDatabase());
* }
* ```
*
* @param halfOpenAfter Time after failures to try to open the circuit
* breaker again.
* @param breaker The circuit breaker to use. This package exports
* ConsecutiveBreaker and SamplingBreakers for you to use.
*/
public circuitBreaker(halfOpenAfter: number, breaker: IBreaker) {
return new CircuitBreakerPolicy(
{
breaker,
halfOpenAfter,
},
new ExecuteWrapper(this.options.errorFilter, this.options.resultFilter),
);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants