mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Added definition for the hystrixjs library
This commit is contained in:
parent
32029fcb4e
commit
ebe527eecc
86
hystrixjs/hystrixjs-tests.ts
Normal file
86
hystrixjs/hystrixjs-tests.ts
Normal file
@ -0,0 +1,86 @@
|
||||
/// <reference path="hystrixjs.d.ts" />
|
||||
/// <reference path="../q/Q.d.ts"/>
|
||||
|
||||
import hystrixjs = require('hystrixjs');
|
||||
import q = require('q');
|
||||
|
||||
var commandFactory = hystrixjs.commandFactory;
|
||||
|
||||
var command = commandFactory
|
||||
.getOrCreate('testCommand', 'testGroup')
|
||||
.circuitBreakerSleepWindowInMilliseconds(5000)
|
||||
.errorHandler((error) => {
|
||||
return false;
|
||||
})
|
||||
.timeout(3000)
|
||||
.circuitBreakerRequestVolumeThreshold(10)
|
||||
.requestVolumeRejectionThreshold(10)
|
||||
.circuitBreakerForceOpened(true)
|
||||
.circuitBreakerForceClosed(false)
|
||||
.statisticalWindowNumberOfBuckets(10)
|
||||
.statisticalWindowLength(10)
|
||||
.percentileWindowNumberOfBuckets(10)
|
||||
.percentileWindowLength(60)
|
||||
.circuitBreakerErrorThresholdPercentage(30)
|
||||
.fallbackTo((error) => {
|
||||
return q.resolve('fallback');
|
||||
})
|
||||
.run((args) => {
|
||||
return q.resolve(args);
|
||||
})
|
||||
.build();
|
||||
|
||||
command.execute('something').then((result) => {
|
||||
console.log(result);
|
||||
})
|
||||
|
||||
commandFactory.resetCache();
|
||||
|
||||
var metricsFactory = hystrixjs.metricsFactory;
|
||||
|
||||
var metrics = metricsFactory.getOrCreate({
|
||||
commandKey: 'metricsKey',
|
||||
commandGroup: 'metricsGroup'
|
||||
})
|
||||
metrics.markSuccess();
|
||||
metrics.markFailure();
|
||||
metrics.markRejected();
|
||||
metrics.markTimeout();
|
||||
metrics.incrementExecutionCount();
|
||||
metrics.decrementExecutionCount();
|
||||
metrics.getCurrentExecutionCount();
|
||||
metrics.addExecutionTime(3000);
|
||||
metrics.getRollingCount("FAILURE");
|
||||
var healthcounts = metrics.getHealthCounts();
|
||||
console.log(healthcounts.totalCount);
|
||||
console.log(healthcounts.errorCount);
|
||||
console.log(healthcounts.errorPercentage);
|
||||
|
||||
metricsFactory.resetCache();
|
||||
|
||||
metricsFactory.getAllMetrics().map((metrics) => {
|
||||
console.log(metrics.getCurrentExecutionCount());
|
||||
});
|
||||
|
||||
var hystrixConfig = hystrixjs.hystrixConfig;
|
||||
console.log(hystrixConfig.metricsPercentileWindowBuckets());
|
||||
console.log(hystrixConfig.circuitBreakerForceClosed());
|
||||
console.log(hystrixConfig.circuitBreakerForceOpened());
|
||||
console.log(hystrixConfig.circuitBreakerSleepWindowInMilliseconds());
|
||||
console.log(hystrixConfig.circuitBreakerErrorThresholdPercentage());
|
||||
console.log(hystrixConfig.circuitBreakerRequestVolumeThreshold());
|
||||
console.log(hystrixConfig.circuitBreakerRequestVolumeThresholdForceOverride());
|
||||
console.log(hystrixConfig.circuitBreakerRequestVolumeThresholdOverride());
|
||||
console.log(hystrixConfig.executionTimeoutInMilliseconds());
|
||||
console.log(hystrixConfig.metricsStatisticalWindowBuckets());
|
||||
console.log(hystrixConfig.metricsStatisticalWindowInMilliseconds());
|
||||
console.log(hystrixConfig.metricsPercentileWindowInMilliseconds());
|
||||
console.log(hystrixConfig.requestVolumeRejectionThreshold());
|
||||
console.log(hystrixConfig.resetProperties());
|
||||
console.log(hystrixConfig.init({}));
|
||||
|
||||
var hystrixSSEStream = hystrixjs.hystrixSSEStream;
|
||||
|
||||
hystrixSSEStream.toObservable().subscribe((result) => {
|
||||
console.log(result);
|
||||
})
|
||||
148
hystrixjs/hystrixjs.d.ts
vendored
Normal file
148
hystrixjs/hystrixjs.d.ts
vendored
Normal file
@ -0,0 +1,148 @@
|
||||
// Type definitions for dragula v2.1.2
|
||||
// Project: https://bitbucket.org/igor_sechyn/hystrixjs
|
||||
// Definitions by: Igor Sechyn <https://github.com/igorsechyn/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
///<reference path="../q/Q.d.ts"/>
|
||||
///<reference path="../rx/rx.d.ts"/>
|
||||
|
||||
declare module HystrixJS {
|
||||
|
||||
interface HystrixProperties {
|
||||
"hystrix.force.circuit.open"?: boolean,
|
||||
"hystrix.force.circuit.closed"?: boolean,
|
||||
"hystrix.circuit.sleepWindowInMilliseconds"?:number,
|
||||
"hystrix.circuit.errorThresholdPercentage"?: number,
|
||||
"hystrix.circuit.volumeThreshold"?:number,
|
||||
"hystrix.circuit.volumeThreshold.forceOverride"?: boolean,
|
||||
"hystrix.circuit.volumeThreshold.override"?: number,
|
||||
"hystrix.execution.timeoutInMilliseconds"?: number,
|
||||
"hystrix.metrics.statistical.window.timeInMilliseconds"?: number,
|
||||
"hystrix.metrics.statistical.window.bucketsNumber"?: number,
|
||||
"hystrix.metrics.percentile.window.timeInMilliseconds"?: number,
|
||||
"hystrix.metrics.percentile.window.bucketsNumber"?: number,
|
||||
"hystrix.request.volume.rejectionThreshold"?: number
|
||||
}
|
||||
|
||||
interface HystrixConfig {
|
||||
metricsPercentileWindowBuckets(): number;
|
||||
circuitBreakerForceClosed(): boolean;
|
||||
circuitBreakerForceOpened(): boolean;
|
||||
circuitBreakerSleepWindowInMilliseconds(): number;
|
||||
circuitBreakerErrorThresholdPercentage(): number;
|
||||
circuitBreakerRequestVolumeThreshold(): number;
|
||||
circuitBreakerRequestVolumeThresholdForceOverride(): boolean;
|
||||
circuitBreakerRequestVolumeThresholdOverride(): number;
|
||||
executionTimeoutInMilliseconds(): number;
|
||||
metricsStatisticalWindowBuckets(): number;
|
||||
metricsStatisticalWindowInMilliseconds(): number;
|
||||
metricsPercentileWindowInMilliseconds(): number;
|
||||
metricsPercentileWindowBuckets(): number;
|
||||
requestVolumeRejectionThreshold(): number;
|
||||
resetProperties(): void;
|
||||
init(properties: HystrixProperties): void;
|
||||
}
|
||||
|
||||
interface Command {
|
||||
execute(...args: any[]): Q.Promise<any>;
|
||||
}
|
||||
|
||||
interface CommandBuilder {
|
||||
circuitBreakerSleepWindowInMilliseconds(value: number): CommandBuilder;
|
||||
errorHandler(value: (error: any) => boolean): CommandBuilder;
|
||||
timeout(value: number): CommandBuilder;
|
||||
circuitBreakerRequestVolumeThreshold(value: number): CommandBuilder;
|
||||
requestVolumeRejectionThreshold(value: number): CommandBuilder;
|
||||
circuitBreakerForceOpened(value: boolean): CommandBuilder;
|
||||
circuitBreakerForceClosed(value: boolean): CommandBuilder;
|
||||
statisticalWindowNumberOfBuckets(value: number): CommandBuilder;
|
||||
statisticalWindowLength(value: number): CommandBuilder;
|
||||
percentileWindowNumberOfBuckets(value: number): CommandBuilder;
|
||||
percentileWindowLength(value: number): CommandBuilder;
|
||||
circuitBreakerErrorThresholdPercentage(value: number): CommandBuilder;
|
||||
run(value: (args: any) => Q.Promise<any>): CommandBuilder;
|
||||
fallbackTo(value: (...args: any[]) => Q.Promise<any>): CommandBuilder;
|
||||
context(value: any): CommandBuilder;
|
||||
build(): Command;
|
||||
}
|
||||
|
||||
interface CommandFactory {
|
||||
getOrCreate(commandKey: string, commandGroup?: string): CommandBuilder;
|
||||
resetCache(): void;
|
||||
}
|
||||
|
||||
interface HealthCounts {
|
||||
totalCount: number;
|
||||
errorCount: number;
|
||||
errorPercentage: number;
|
||||
}
|
||||
|
||||
interface CommandMetrics {
|
||||
markSuccess(): void;
|
||||
markRejected(): void;
|
||||
markFailure(): void;
|
||||
markTimeout(): void;
|
||||
markShortCircuited(): void;
|
||||
incrementExecutionCount(): void;
|
||||
decrementExecutionCount(): void;
|
||||
getCurrentExecutionCount(): number;
|
||||
addExecutionTime(value: number): void;
|
||||
getRollingCount(type: any): number;
|
||||
getExecutionTime(percentile: any): number;
|
||||
getHealthCounts(): HealthCounts;
|
||||
reset(): void;
|
||||
}
|
||||
|
||||
interface MetricsProperties {
|
||||
commandKey: string,
|
||||
commandGroup: string,
|
||||
statisticalWindowTimeInMilliSeconds?: number,
|
||||
statisticalWindowNumberOfBuckets?: number,
|
||||
percentileWindowTimeInMilliSeconds?: number,
|
||||
percentileWindowNumberOfBuckets?: number
|
||||
}
|
||||
|
||||
interface MetricsFactory {
|
||||
getOrCreate(config: MetricsProperties): CommandMetrics;
|
||||
resetCache(): void;
|
||||
getAllMetrics(): Array<CommandMetrics>;
|
||||
}
|
||||
|
||||
interface CirctuiBreakerConfig {
|
||||
circuitBreakerSleepWindowInMilliseconds: number,
|
||||
commandKey: string,
|
||||
circuitBreakerErrorThresholdPercentage: number,
|
||||
circuitBreakerRequestVolumeThreshold: number,
|
||||
commandGroup: string,
|
||||
circuitBreakerForceClosed: boolean,
|
||||
circuitBreakerForceOpened: boolean
|
||||
}
|
||||
|
||||
interface CircuitBreaker {
|
||||
allowRequest(): boolean;
|
||||
allowSingleTest(): boolean;
|
||||
isOpen(): boolean;
|
||||
markSuccess(): void;
|
||||
}
|
||||
|
||||
interface CircuitFactory {
|
||||
getOrCreate(config: CirctuiBreakerConfig): CircuitBreaker;
|
||||
getCache(): Array<CircuitBreaker>;
|
||||
resetCache(): void;
|
||||
}
|
||||
|
||||
interface HystrixSSEStream {
|
||||
toObservable(): Rx.Observable<any>
|
||||
}
|
||||
}
|
||||
declare var hystrixjs: {
|
||||
commandFactory: HystrixJS.CommandFactory,
|
||||
metricsFactory: HystrixJS.MetricsFactory,
|
||||
circuitFactory: HystrixJS.CircuitFactory,
|
||||
hystrixSSEStream: HystrixJS.HystrixSSEStream,
|
||||
hystrixConfig: HystrixJS.HystrixConfig
|
||||
};
|
||||
|
||||
declare module "hystrixjs" {
|
||||
export = hystrixjs;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user