Skip to content

Instantly share code, notes, and snippets.

@scribblet
Created December 27, 2013 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scribblet/8144899 to your computer and use it in GitHub Desktop.
Save scribblet/8144899 to your computer and use it in GitHub Desktop.
Example task runner
//makeThumbnail.js
module.exports = {
start : function(input, db){
// makeThumbnail
// save timestamp
db.save({...});
}
};
//uploadToS3.js
module.exports = {
start : function(input, db){
// upload thumb
// perhaps save bucket name
db.save({...});
}
};
//taskRunner.js
var db = require('./database.js'),
tasks = {},
taskToRun = process.argv[2],
taskRunner;
tasks.makeThumbnail = require('./tasks/makeThumbnail');
tasks.uploadToS3 = require('./tasks/uploadToS3');
taskRunner = function(task){
task.start(process.argv, db);
};
if ( taskToRun in tasks ) {
taskRunner( tasks[taskToRun] );
} else {
// error handling
}
// makeThumbnail.test.js
var makeThumbnail = require('makeThumbnail');
describe('Make Thumbnail', function(){
var database = {};
it('should make a thumbnail, and call db.save', function(done){
var input = {
imageId : 1
};
database.save = function(obj){
assert.equal(obj.id, input.imageId);
done();
}
makeThumbnail(input, database);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment