Crazy simple redis-backed scheduling
###Crazy simple redis-backed scheduling.###
QueuePasa makes it super easy to schedule messages to be delivered at a later time/date.
It's as easy as this:
qpasaschedule'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:
qpasaschedule'Hey' '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.
qpasaschedule'Hey' 1367892625698; //Bad! Your message will be delivered in a few decades!qpasaschedule'Hey' "1367892625698"; //However, this works as expected. Just be careful.
var QueuePasa = require'queuepasa'//These are the current options and their defaults...qpasa =host: '127.0.0.1'port: 6379groupBy: 'day'interval: 5000delayMultiplier: 1prefix: 'qp';qpasaon'item'console.log'New message: %s' item;;qpasaschedule'Hey' 'May 07 2013 8:00 PM'//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;;qpasaremove123 'May 07 2013 8:00 PM'//If an error occured...;
Couldn't be easier.
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
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
default = 'qp'