Monitor SQS tasks and batches using redis.
npm install ya-sqs-monitor
var sqs = require('ya-sqs');
var Monitor = require('ya-sqs-monitor');
// Create a basic queue.
var queue = sqs.createQueue({
aws: {
region: 'eu-west-1',
accessKeyId: '...',
secretAccessKey: '...'
},
name: 'sqs-monitor-test'
});
// Create a monitor.
var monitor = new Monitor(options);
// Monitor queue to to get updates.
monitor.watch(queue);
// Push tasks linked to the same batch.
queue.push({batchId: 'my-batch', data: 'my message'});
queue.push({batchId: 'my-batch', data: 'my second message'});
// Get progression of the batch.
monitor.info('my-batch').then(function (info) {
console.log(info); // {progress: 0.4, total: 100, processed: 40}
});
Create a new monitor with some options.
Type: Object
or Function
If you specify an object, the properties will be used to call redis.createClient
method.
new Monitor({
redis: {
port: 6379,
host: '127.0.0.1',
connect_timeout: 200
}
})
If you specify a function, it will be called to create redis clients.
var redis = require('redis');
new Monitor({
redis: createClient
})
function createClient() {
var client = redis.createClient();
client.select(1); // Choose a custom database.
return client;
}
Custom prefix for redis key. Defaults to "sqsmon".
new Monitor({prefix: 'custom-prefix'})
Watch a queue in order to update batch in redis. You must watch a queue either you push into the queue or if you pull the queue.
monitor.watch(queue);
Get the state of the batch (total, processed and progress). This method supports promises and callback.
monitor.get('my-batch').then(function (info) {
console.log('info'); // {total: 10, processed: 4, progress: 0.4}
});
MIT