Code coverage report for node/src/circuit/hystrix.ts

Statements: 25% (2 / 8)      Branches: 0% (0 / 2)      Functions: 0% (0 / 2)      Lines: 25% (2 / 8)      Ignored: none     

All files » node/src/circuit/ » hystrix.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 451                                                 1                                      
import {commandFactory} from 'hystrixjs';
import {CommandFactory, CommandOptions, Command} from '@btilford/ts-base-core';
 
export type HystrixCommandOptions = CommandOptions & {
  timeout?: number;
  errorHandler?: (err: unknown, ...args: unknown[]) => unknown;
  fallbackTo?: (err: unknown, ...args: unknown[]) => unknown;
  cleanup?: unknown;
  context?: unknown;
 
  circuitBreakerErrorThresholdPercentage?: number;
  circuitBreakerRequestVolumeThreshold?: number;
  circuitBreakerSleepWindowInMilliseconds?: number;
  circuitBreakerForceOpened?: unknown;
  circuitBreakerForceClosed?: unknown;
 
  statisticalWindowLength?: number;
  statisticalWindowNumberOfBuckets?: number;
  percentileWindowNumberOfBuckets?: number;
  percentileWindowLength?: number;
 
 
  requestVolumeRejectionThreshold?: unknown;
}
 
export class HystrixCommandFactory implements CommandFactory {
 
  constructor(readonly group?: string) {
  }
 
  build<T>(options: HystrixCommandOptions): Command<T> {
    let builder = commandFactory.getOrCreate(options.name, this.group);
 
    for (const [k, v] of Object.entries(options)) {
      if (typeof builder[k] === 'function') {
        builder = builder[k](v);
      }
    }
 
    return builder.build();
  }
 
}