lib/index.js
/**
 * create hystrix command
 * @param  {Function} func function to execute
 * @param  {Object} service service object
 * @return {Function} returns generated hystrix command
 */
create hystrix command
@param  {Function} func function to execute
@param  {Object} service service object
@return {Function} returns generated hystrix command
create hystrix command @param { Function } func function to execute @param { Object } service service object @return { Function } returns generated hystrix command
function createServiceCommand(func, service, functionName, circuitBreakerImpl = DEFAULT_CIRCUIT_BREAKER) {
  let name = func.name && service && service.name && !service.name.includes(':') && !service.name.includes(func.name)
    ? `${service.name}:${func.name}`
    : service && service.name && func.name && !service.name.includes(func.name)
      ? `${service.name}:${func.name}`
      : service && service.name;
  if (functionName && !name.includes(functionName)) {
    name = `${service.name}:${functionName}`;
  }
  const options = {
    timeout: service && service.timeout || 3000, 
    errorThresholdPercentage: service && service.errorThreshold || 50, 
    resetTimeout: service && service.cbsleep || 3000, 
    rollingCountTimeout: service && service.statisticalWindowLength || 10000,
    rollingCountBuckets: service && service.statisticalWindowNumberOfBuckets || 10,
    name: name,
    capacity: service && service.cbRequestVolume || 10,
    circuitDuration: service && service.cbsleep || 3000,
    bucketNum: service && service.statisticalWindowNumberOfBuckets || 10,
    threshold: service && service.errorThreshold || 0.5,
    isFailure: service && service.isFailure || onFailure,
    failure: service && service.isFailure || onFailure,
    modifyError: false
  };
  if (circuitBreakerImpl === 'opossum') {
    return circuitBreaker(
      func,
      options
    );
  }
  return new Brakes(
    func,
    options
  );
}
function createServiceCommand ( func , service , functionName , circuitBreakerImpl = DEFAULT_CIRCUIT_BREAKER ) { let name = func . name && service && service . name && ! service . name . includes ( ':' ) && ! service . name . includes ( func . name ) ? ` ${ service . name } ${ func . name } ` : service && service . name && func . name && ! service . name . includes ( func . name ) ? ` ${ service . name } ${ func . name } ` : service && service . name ; if ( functionName && ! name . includes ( functionName ) ) { name = ` ${ service . name } ${ functionName } ` ; } const options = { timeout : service && service . timeout || 3000 , errorThresholdPercentage : service && service . errorThreshold || 50 , resetTimeout : service && service . cbsleep || 3000 , rollingCountTimeout : service && service . statisticalWindowLength || 10000 , rollingCountBuckets : service && service . statisticalWindowNumberOfBuckets || 10 , name : name , capacity : service && service . cbRequestVolume || 10 , circuitDuration : service && service . cbsleep || 3000 , bucketNum : service && service . statisticalWindowNumberOfBuckets || 10 , threshold : service && service . errorThreshold || 0.5 , isFailure : service && service . isFailure || onFailure , failure : service && service . isFailure || onFailure , modifyError : false } ; if ( circuitBreakerImpl === 'opossum' ) { return circuitBreaker ( func , options ) ; } return new Brakes ( func , options ) ; }
create hystrix command
 @param  {Function} func function to execute
 @param  {Object} service service object
 @return {Function} returns generated hystrix command
create hystrix command @param { Function } func function to execute @param { Object } service service object @return { Function } returns generated hystrix command
// If our function takes longer than 3 seconds, trigger a failure // When 50% of requests fail, trip the circuit // After 30 seconds, try again.