Skip to content

Instantly share code, notes, and snippets.

@jonstorer
Last active August 29, 2015 14:10
Show Gist options
  • Save jonstorer/93f5f931ae15366c1b76 to your computer and use it in GitHub Desktop.
Save jonstorer/93f5f931ae15366c1b76 to your computer and use it in GitHub Desktop.
workers.js
var winston = require('winston')
, kue = require('kue')
, workers = require('./app/workers')
, queue = require('./config/queue');
Object.keys(workers).forEach(function(name){
Object.keys(workers[name]).forEach(function(task){
queue.process(name + '/' + task, 20, function(job, done){
var args = job.data.args || [];
args.push(function(err){
if(err){ handleErr(err) };
winston.info('end', job.id, job.type, job.data.title);
done();
});
winston.info('start', job.id, job.type, job.data.title);
workers[name][task].apply(job, args);
});
});
});
// Test
var sinon = require('sinon')
, expect = require('chai').expect
, queueCallback = sinon.spy();
sinon.stub(queue, 'process', function(type, num, task){
for(id in this.jobs){
var job = this.jobs[i];
if(job.type == type){
task.call(null, job, queueCallback);
}
}
});
expect(queueCallback.getCall(0).args[0]).to.be.instanceOf(Error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment