task queue component for (mobile) browser backed by localstorage
$ component install pgherveou/queue
var queue = require('queue')
.on('error', function(job) {}) // queue error handler
.on('complete', function(job) {}); // queue success handler
// define a new task
queue
.define('my-task')
.online() // check that navigator is online before attempting to process job
.interval('10s') // replay a failed job every 10sec (default is 2sec)
.retry(5) // retry up to 5 times
.delay('5ms') // start task after a 5ms delay
.timeout('10ms') // task fail if it lasts more than 10ms
.lifetime('5m') // stop retrying if job is more than 5min old
.action(function(job, done) {
// ...
done(err); // pass an error to the callback if task failed
});
// load and process jobs persisted in the localstorage
queue.start();
// process a new job
job = queue
.create('my-task', data)
.on('error', function() {}) // job error handler
.on('complete', function() {}) // job success handler
get the default queue instance
create a new queue with specific id localstorage keys will be prefixed with queue-[id]
define a new Task with given name
Queue is an event emitter, whenever a job fail or complete an error or complete event is triggered
check that navigator is online before attempting to process job
define the interval between two retries (default is '2sec')
define max number of retries
define task timeout
define task delay
a job expires if it exceeds creation-time + time
action to execute receive a job and a callback
MIT