queuepasa

1.1.2 • Public • Published

QueuePasa

###Crazy simple redis-backed scheduling.###

QueuePasa makes it super easy to schedule messages to be delivered at a later time/date.

Scheduling

It's as easy as this:

qpasa.schedule('Hey', 60000); //This will deliver the message 'Hey' in 60,000ms (1 minute).

You can also schedule an exact date and time to deliver instead. Just pass a Date object instead of a delay:

qpasa.schedule('Hey', new Date('May 07 2013 8:00 PM'));

Warning: Don't pass a unix timestamp as an integer (a string is fine) because it will be interpreted as a delay.

qpasa.schedule('Hey', 1367892625698); //Bad! Your message will be delivered in a few decades!
qpasa.schedule('Hey', "1367892625698"); //However, this works as expected. Just be careful.

Usage

var QueuePasa = require('queuepasa'),
    //These are the current options and their defaults...
    qpasa = new QueuePasa({
      host: '127.0.0.1',
      port: 6379,
      groupBy: 'day',
      interval: 5000,
      delayMultiplier: 1,
      prefix: 'qp'
    });

qpasa.on('item', function(item) {
  console.log('New message: %s', item);
});

qpasa.schedule('Hey', new Date('May 07 2013 8:00 PM'), function(err, id, scheduleDate) {
  //Optional callback gives you the queue ID (Int) and scheduleDate (Date Object)
  //...both are required to remove the item from the queue, so keep them safe!
  console.log('Alright, %s is queued up for %s.', id, scheduleDate);
});

qpasa.remove(123, new Date('May 07 2013 8:00 PM'), function(err) {
  //If an error occured...
});

Couldn't be easier.

Options

The options object isn't necessary. You can just use new QueuePasa() if the defaults are to your liking.

host: Where is the Redis instance? default = '127.0.0.1'

port: The Redis port. default = 6379

groupBy: QueuePasa speeds things up by placing your queued items in buckets by day. If you have a high volume, you can change this to hour. default = 'day'

interval: How often to check for messages. default = 5000

delayMultiplier: You can have your delay number multiplied. For example, set delayMultiplier to 60000 then your delay argument will be interpreted as minutes instead of miliseconds. default = 1

prefix: The first part of the bucket name. Buckets look something like qp:2013-05-07:z. default = 'qp'

Readme

Keywords

none

Package Sidebar

Install

npm i queuepasa

Weekly Downloads

2

Version

1.1.2

License

none

Last publish

Collaborators

  • kevinmctigue