How to use the bottleneck.Group 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 octokit / plugin-throttling.js / test / integration / index.js View on Github external
it('Should maintain 2000ms between search requests', async function () {
    const octokit = new Octokit({
      throttle: {
        search: new Bottleneck.Group({ minTime: 50 }),
        onAbuseLimit: () => 1,
        onRateLimit: () => 1
      }
    })

    const req1 = octokit.request('GET /search/route1', {
      request: {
        responses: [{ status: 201, headers: {}, data: {} }]
      }
    })
    const req2 = octokit.request('GET /route2', {
      request: {
        responses: [{ status: 202, headers: {}, data: {} }]
      }
    })
    const req3 = octokit.request('GET /search/route3', {
github octokit / plugin-throttling.js / test / integration / index.js View on Github external
it('Should optimize throughput rather than maintain ordering', async function () {
    const octokit = new Octokit({
      throttle: {
        write: new Bottleneck.Group({ minTime: 50 }),
        notifications: new Bottleneck.Group({ minTime: 150 }),
        onAbuseLimit: () => 1,
        onRateLimit: () => 1
      }
    })

    const req1 = octokit.request('POST /orgs/abc/invitations', {
      request: {
        responses: [{ status: 200, headers: {}, data: {} }]
      }
    })
    const req2 = octokit.request('GET /route2', {
      request: {
        responses: [{ status: 200, headers: {}, data: {} }]
      }
    })
    const req3 = octokit.request('GET /route3', {
github octokit / plugin-throttling.js / test / integration / retry.js View on Github external
it('Should retry \'rate-limit\' and succeed', async function () {
      let eventCount = 0
      const octokit = new Octokit({
        throttle: {
          write: new Bottleneck.Group({ minTime: 50 }),
          onRateLimit: (retryAfter, options) => {
            expect(options).to.include({ method: 'POST', url: '/graphql' })
            expect(options.request.retryCount).to.equal(eventCount)
            expect(retryAfter).to.equal(0)
            eventCount++
            return true
          },
          onAbuseLimit: () => 1
        }
      })

      const res = await octokit.request('POST /graphql', {
        request: {
          responses: [
            { status: 200, headers: { 'x-ratelimit-remaining': '0', 'x-ratelimit-reset': '123' }, data: { errors: [{ type: 'RATE_LIMITED' }] } },
            { status: 200, headers: {}, data: { message: 'Yay!' } }
github octokit / plugin-throttling.js / test / integration / index.js View on Github external
it('Should maintain 1000ms between mutating or GraphQL requests', async function () {
    const octokit = new Octokit({
      throttle: {
        write: new Bottleneck.Group({ minTime: 50 }),
        onAbuseLimit: () => 1,
        onRateLimit: () => 1
      }
    })

    const req1 = octokit.request('POST /route1', {
      request: {
        responses: [{ status: 201, headers: {}, data: {} }]
      }
    })
    const req2 = octokit.request('GET /route2', {
      request: {
        responses: [{ status: 202, headers: {}, data: {} }]
      }
    })
    const req3 = octokit.request('POST /route3', {

bottleneck

Distributed task scheduler and rate limiter

MIT
Latest version published 5 years ago

Package Health Score

67 / 100
Full package analysis