Skip to content

Instantly share code, notes, and snippets.

@mlevkovsky
Created December 9, 2020 18:09
Show Gist options
  • Save mlevkovsky/d1ed68e8eb73c509f8fb91f2898c1c68 to your computer and use it in GitHub Desktop.
Save mlevkovsky/d1ed68e8eb73c509f8fb91f2898c1c68 to your computer and use it in GitHub Desktop.
circuit breaker decorator example
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