Created
December 9, 2020 18:09
-
-
Save mlevkovsky/d1ed68e8eb73c509f8fb91f2898c1c68 to your computer and use it in GitHub Desktop.
circuit breaker decorator example
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
import { CircuitBreaker } from '@ssense/circuit-breaker'; | |
@CircuitBreaker.wrap({ | |
timeout: 5000, | |
errorThresholdPercentage: 55, | |
resetTimeout: 15000, | |
rollingCountTimeout: 10000, | |
volumeThreshold: 3, | |
fallback: (thisObject: ProductGateway) => thisObject.cbFallback, | |
}) | |
public async getProductsByIds(requestId: string, entry: GetProductsByIdsInterface): Promise<Product[]> { | |
// do some stuff to prepare request... | |
const response = (await fetch(requestId, 'https://product-service/products/search', 'GET')).body; | |
return response.products ? response.products : []; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment