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();
}
}
|