How to use the bottleneck.strategy function in bottleneck

To help you get started, we’ve selected a few bottleneck examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NorthernMan54 / homebridge-alexa / lib / alexaLocal.js View on Github external
function alexaLocal(options) {
  debug("Connecting to Homebridge Smart Home Skill");
  // Throttle event's to match Amazon's Rate API
  // Limit events to one every 30 seconds, and keep at most 5 minutes worth
  limiter = new Bottleneck({
    maxConcurrent: 1,
    highWater: 10,
    minTime: 10000,
    strategy: Bottleneck.strategy.BLOCK
  });

  limiter.on("dropped", function(dropped) {
    console.log("WARNING: ( homebridge-alexa) Dropped event message, message rate too high.");
  });

  username = options.username;
  connection.client = mqtt.connect(options);
  // connection.client.setMaxListeners(0);
  connection.client.on('connect', function() {
    debug('connect', "command/" + options.username + "/#");
    connection.client.removeAllListeners('message'); // This hangs up everyone on the channel
    connection.client.subscribe("command/" + options.username + "/#");
    connection.client.publish("presence/" + options.username + "/1", JSON.stringify({
      Connected: options.username,
      version: packageConfig.version
github macarthur-lab / gnomadjs / projects / gnomad-api / src / server.js View on Github external
const app = express()
app.use(compression())
app.use(cors())

app.set('trust proxy', JSON.parse(process.env.TRUST_PROXY || 'false'))

const elastic = new elasticsearch.Client({
  apiVersion: '5.5',
  host: process.env.ELASTICSEARCH_URL,
})

const esLimiter = new Bottleneck({
  maxConcurrent: JSON.parse(process.env.MAX_CONCURRENT_ES_REQUESTS || '100'),
  highWater: JSON.parse(process.env.MAX_QUEUED_ES_REQUESTS || '1000'),
  strategy: Bottleneck.strategy.OVERFLOW,
})

esLimiter.on('error', error => {
  logger.error(error)
})

const warnRequestTimedOut = throttledWarning(n => `${n} ES requests timed out`, 60000)
const warnRequestDropped = throttledWarning(n => `${n} ES requests dropped`, 60000)

const scheduleElasticsearchRequest = fn => {
  return new Promise((resolve, reject) => {
    let canceled = false

    // If task sits in the queue for more than 30s, cancel it and notify the user.
    const timeout = setTimeout(() => {
      canceled = true
github macarthur-lab / gnomadjs / projects / exome-results-browsers / src / server / server.js View on Github external
;(async () => {
  const elastic = new elasticsearch.Client({
    apiVersion: '5.5',
    host: process.env.ELASTICSEARCH_URL,
  })

  const esLimiter = new Bottleneck({
    maxConcurrent: JSON.parse(process.env.MAX_CONCURRENT_ES_REQUESTS || '100'),
    highWater: JSON.parse(process.env.MAX_QUEUED_ES_REQUESTS || '1000'),
    strategy: Bottleneck.strategy.OVERFLOW,
  })

  esLimiter.on('error', error => {
    logger.error(error)
  })

  const warnRequestTimedOut = throttledWarning(n => `${n} ES requests timed out`, 60000)
  const warnRequestDropped = throttledWarning(n => `${n} ES requests dropped`, 60000)

  const scheduleElasticsearchRequest = fn => {
    return new Promise((resolve, reject) => {
      let canceled = false

      // If task sits in the queue for more than 30s, cancel it and notify the user.
      const timeout = setTimeout(() => {
        canceled = true
github stef-levesque / vscode-perforce / src / PerforceService.ts View on Github external
if (!trailingSlash.exec(compareDir)) compareDir += '/';
    
    if (config.localDir === compareDir) {
        return true;
    }

    return false;
}

export namespace PerforceService {

    const limiter: Bottleneck = new Bottleneck({
        maxConcurrent:  workspace.getConfiguration('perforce').get('bottleneck.maxConcurrent'),
        minTime:        workspace.getConfiguration('perforce').get('bottleneck.minTime'),
        highWater:      workspace.getConfiguration('perforce').get('bottleneck.highWater'),
        strategy:       Bottleneck.strategy[
                            workspace.getConfiguration('perforce').get('bottleneck.strategy')
                        ],
        penalty:        workspace.getConfiguration('perforce').get('bottleneck.penalty'),
    });

    const debugModeActive: boolean = workspace.getConfiguration('perforce').get('debugModeActive');

    let debugModeSetup: boolean = false;

    let _configs: {[key: string]: IPerforceConfig} = {};

    export function addConfig(inConfig: IPerforceConfig, workspacePath: string): void {
        _configs[workspacePath] = inConfig;
    }
    export function removeConfig(workspacePath: string): void {
        delete _configs[workspacePath];

bottleneck

Distributed task scheduler and rate limiter

MIT
Latest version published 5 years ago

Package Health Score

67 / 100
Full package analysis