1.0.0 • Published 2 months ago

http-resilient-executor v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

http-resilient-executor

Helper for creating retry policies , circuit breaker for functions and external requests

Config

NameDescription
httpResilienceCBHalfOpenAfterMSIndicates the Time CircuitBreaker to be in half open state
httpResilienceRetryCountRetry count for requests
httpResilienceCBConsecutiveThresholdMaximum attempts to open CircuitBreaker

For logger configuration properties see the logger documentation

Usage

// init ResilientExecutor instance (should use 1 instance per app)
import { ResilientExecutor } from 'http-resilient-executor';

const config = {
  /** logger configuration */
  logger: { logLevel: 'cli', logStyle: 'debug', appName: 'nodejs-commons',moduleName: 'ResilientExecutor' },

  /** After 10 seconds the CB will be half open state */
  httpResilienceCBHalfOpenAfterMS: 10 * 1000,

  /** After 5 consecutive failed requests, the CB will be open */
  httpResilienceCBConsecutiveThreshold: 5,

  /**  Retry count for failed requests */
  httpResilienceRetryCount: 3,
};

const resilientExec = new ResilientExecutor(config);

/** use resilientExecutor to wrap functions and api calls */
/** to wrap function */
await resilientExec.execute(testMock);

/** to wrap api */

await this.executor.execute(() =>
        axios.post(this.authUrl, params,
        {
          headers: { 'Content-Type': 'application/x-www-form-urlencoded'},
          auth: credentials,
        }),
      );
1.0.0

2 months ago