Skip to content

balena-io-modules/requestqueue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

requestqueue

npm version dependencies

npm

Run requests in sequence and retry them if they fail using request-retry module.

This is useful when requests need to be send in a guaranteed order, for example when sending status updates.

The response should not be expected to arrive immediately (nor soon), since there may be other requests in the queue or the response may arrive after several retries.

Installation

$ npm install requestqueue

Example

RequestQueue = require('requestqueue');

// Set default maxAttempts and retryDelay for this queue
// Also sets an error handler in case a request exceeds maxAttempts
queue = RequestQueue({ 
	maxAttempts: 5, 
	retryDelay: 1000, 
	errorHandler: function (err) {
		console.error('A request could not be completed:', err.message)
	}
});

// Queue a request, the arguments are passed to request-retry module.
queue.push( {
	method: 'GET',
	url: 'http://www.google.com'
	maxAttempts: 3600,
	retryDelay: 1000,
	callback: function (err, response, body) {
		console.log('got response body', body);
	}
} );

Support

If you're having any problem, please raise an issue on GitHub and the Resin.io team will be happy to help.

Tests

Run the test suite by doing:

$ npm install && npm test

Contribute

Before submitting a PR, please make sure that you include tests, and that coffeelint runs without any warning.

License

The project is licensed under the MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published