adaptive-throttling-with-retry
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Adaptive throttling

npm-version bundle-size node-version downloads

This library is an extension for adaptive-throttling library that provides simple retry based on request rejection probability

Installation

npm i adaptive-throttling-with-retry -S

or

yarn add adaptive-throttling-with-retry

Usage

Import

import { AdaptiveThrottlingWithRetry } from 'adaptive-throttling-with-retry';
// or
const { AdaptiveThrottlingWithRetry } = require('adaptive-throttling-with-retry');

Example

const { AdaptiveThrottling } = require('adaptive-throttling-with-retry');
const axios = require('axios');

const adaptiveThrottlingWithRetry = AdaptiveThrottlingWithRetry({
  historyTimeMinute: 120,
  k: 2,
  upperLimiteToReject: 60,
  retries: 3,
  retryDelayMultiplier: 2,
  maxRetryDelay: 200,
  upperProbabilityLimiteToRetry: 0.4,
});

adaptiveThrottlingWithRetry
  .execute(() => {
    return axios.get('/user?ID=12345');
  })
  .then((response) => {
    console.log('success', response.data);
  })
  .catch((error) => {
    console.log('error', error.message);
  });

Or use any retry library you want

const { AdaptiveThrottling } = require('adaptive-throttling-with-retry');
const axios = require('axios');
const { retry } = require('ts-retry-promise');

const adaptiveThrottlingWithRetry = AdaptiveThrottlingWithRetry({
  backof: 'EXPONENTIAL',
  retryPlugin: (requestFn, options) => {
    return retry(requestFn, options);
  },
  upperProbabilityLimiteToRetry: 0.5,
});

adaptiveThrottlingWithRetry
  .execute(() => {
    return axios.get('/user?ID=12345');
  })
  .then((response) => {
    console.log('success', response.data);
  })
  .catch((error) => {
    console.log('error', error.message);
  });

Package Sidebar

Install

npm i adaptive-throttling-with-retry

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

211 kB

Total Files

12

Last publish

Collaborators

  • fabriciogoncalves