DBQueue
A simple job queue that has priorities other than speed and scalability, inspired by TheSchwartz
Usage
See usage in the tests, or see below example:
var DBQueue = require('dbqueue');
var queue_options = {
host: '127.0.0.1',
port: 3306,
user: 'root',
table_name: 'custom_jobs_table',
password: '',
database: 'dbqueue_testing_db',
};
DBQueue.connect(queue_options, function(err, queue) {
if (err) {
}
var job_details = {
example: 'job data',
};
queue.insert('queue_name_here', JSON.stringify(job_details), function(err) {
if (err) {
}
});
queue.consume('queue_name_here', function(err, job, finished) {
if (err) {
}
if (!job) {
}
var job_data = JSON.parse(job);
finished(some_err);
finished(null, function(err) {
if (err) {
}
});
});
});
When this might be a useful library
- When you don't want to introduce another dependency for simple/trivial functionality
- When you need a durable queue
When this is NOT the solution for you
- You need guarantees that a job will be delivered once (your jobs are not idempotent)
- You need near-realtime performance
- You need to scale to large numbers of jobs
Performance improvements
- fetch batches of jobs rather than one at a time
- when #pop is called
- and we have no items in the working batch
- look for N jobs to work on
- reserve them all
- shift the first off and return it
- and we do have items in the working batch
- shift the first off and return it
- reserve another N ?
- so long as we can process the jobs quickly, this should be okay
- but if we're too slow, we might have stale jobs that someone else is working on