Ratelimit

Circuit
Ratelimit
Ratelimit Duration

Usage

Ratelimit is used to avoid sending too many requests to the backend during a configurable period of time.

If you don't want more than 3 requests per second, you should define a circuit like this:

const ratelimit = new Mollitia.Ratelimit({
  limitPeriod: 1000,
  limitForPeriod: 3,
  logger
});
const circuit = new Mollitia.Circuit({
  options: {
    modules: [
      ratelimit
    ]
  }
});

If you don't want more than 3 requests per second, and also at least 200ms between each request, you should define a circuit like this:

const ratelimit = new Mollitia.Ratelimit({
  limitPeriod: 1000,
  limitForPeriod: 3,
  logger
});
const ratelimit2 = new Mollitia.Ratelimit({
  limitPeriod: 200,
  limitForPeriod: 1,
  logger
});
const circuit = new Mollitia.Circuit({
  options: {
    modules: [
      ratelimit2,
      ratelimit
    ]
  }
});

Options

NameDescriptionDefault
limitPeriodSpecifies the time period during which the ratelimit is calculated0
limitForPeriodSpecifies the maximum number of requests during the periodInfinity

Events

NameDescriptionParams
executeCalled when the module is executed.Mollitia.Circuit circuit

Methods

NameDescriptionReturns
getExecParamsReturns the circuit function parameters.any[] params