npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cape-baboon

v1.5.1

Published

Request throttler for http requests against enemy webservices with unpredictable behavior for mass requests.

Downloads

36

Readme

npm version npm Build Status

NPM

cape-baboon

The cape baboon is a node module for mass requests to helpless enemy servers. Baboons with Car

It throttles requests and retries them until they are completed regardless of limits and restrictions of the enemy server.

Installation

in console:

npm install cape-baboon

and in file:

var CapeBaboon = require('cape-baboon');

Usage

creating a queue

with standard configuration:

var baboon = new CapeBaboon();

with own config:

var baboon = new CapeBaboon({
  RETRY_TIMEOUT: 1000,
  LIMIT_PER_SECOND: 10
});

enqueue

There are two ways of enqueueing a request.

  1. The first way is creating a wrapper function for the call and the pushing it to the queue:
var requestCall = function(){
  return Request('http://www.google.de')
};

baboon.push(requestCall);
  1. The second way is using the more handy build in request method:
var requestOptions = {
  uri: 'http://www.google.de'
};
baboon.request(requestOptions);

The Cape baboon uses the request-promise node-module. Please refer to: request-promise for documentation.

Configuration

You can configure every baboon queue with initializing it with a options object. All the options are, as you might have guessed, optional. This is the standard configuration:

var options = {
  RETRY_TIMEOUT     : 1000,         // the time to wait for retrying a request
  LIMIT_PER_SECOND  : 10,           // how many requests are available per second.
                                    // rule of thumb: 4.0 * 1000/LIMIT_PER_SECOND
  SLOT_RESPAWN      : 4000,         // Time in miliseconds for respawning the slots
  TOO_MANY_REQUESTS : 429,          // The return Status from the Server if there are too many request sent to it. If applicable.
  INFLIGHT          : 'inflight',   // Status while the request call is active
  FULFILLED         : 'fulfilled',  // Status when the request was successfull
  THROTTLED         : 'throttled',  // Status when the request gets throttled
  ERRORED           : 'errored',    // Status when the request has thrown an internal error
  RETRY_ERRORED     : false,        // whether to retry a request if it throws an internal error or not
  RETRY_FAILED      : false,        // whether to retry a request if it returns an http error code

  // Logger function
  LOGGER            : function(text){console.log(text);}
};

Examples

var CapeBaboon = require('./../src/cape-baboon');
var Request = require('request-promise');

// use standard options
var options = {};

// init CapeBaboon Queue
var baboon = new CapeBaboon(options);

// define request call
var requestCall = function(){
  return Request('http://www.google.de')
};

// give the request call to the baboon
baboon.push(requestCall);

// push returns a promise so you can chain it. the result is the result from the request call
baboon.push(requestCall)
        .then(function(result){
                console.log(result);
              }
        );

// the more handy way of request abstraction.
// the request are build with the request-promise module. View https://www.npmjs.com/package/request-promise for documentation
var requestOptions = {
  uri: 'http://www.google.de'
};

// .request fires the request-promise method wrapped in a request call function
baboon.request(requestOptions);

// with promise chain
baboon.request(requestOptions)
    .then(function (htmlString) {
        // Process html...
    })
    .catch(function (err) {
        // Crawling failed...
    });

How it works

How it works

Thanks

The original code is written by @agento and the module is enhanced and maintained by @jbinsen. Special thanks to @LewisCowper for reviewing and testing.