mongopatch
Advanced tools
Comparing version 0.5.1 to 0.5.2
{ | ||
"name": "mongopatch", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"repository": "git://github.com/e-conomic/mongopatch.git", | ||
@@ -5,0 +5,0 @@ "description": "MongoDB patching tool", |
var util = require('util'); | ||
var mongojs = require('mongojs'); | ||
@@ -6,2 +7,3 @@ var stream = require('stream-wrapper'); | ||
var moment = require('moment'); | ||
var async = require('async'); | ||
@@ -32,3 +34,10 @@ var streams = require('./streams'); | ||
var that = stream.passThrough({ objectMode: true }); | ||
var that = stream.transform({ objectMode: true }, | ||
function(data, encoding, callback) { | ||
callback(null, data); | ||
}, | ||
function(callback) { | ||
teardown(callback); | ||
}); | ||
var progress = { | ||
@@ -78,21 +87,20 @@ total: 0, | ||
var setup = function() { | ||
var setup = function(callback) { | ||
if(!that._version || !semver.eq(that._version, packageJson.version)) { | ||
return that.emit('error', new Error(util.format('Specified version (%s) does not match current system version (%s)', | ||
that._version, packageJson.version))); | ||
var err = new Error(util.format('Specified version (%s) does not match current system version (%s)', that._version, packageJson.version)); | ||
return callback(err); | ||
} | ||
if(!that._update) { | ||
return that.emit('error', new Error('Update missing')); | ||
return callback(new Error('Update missing')); | ||
} | ||
var callback = that._setup || function(fn) { | ||
var setupCallback = that._setup || function(fn) { | ||
fn(); | ||
}; | ||
callback(function(err) { | ||
setupCallback(function(err) { | ||
if(err) { | ||
return that.emit('error', err); | ||
return callback(err); | ||
} | ||
that.on('end', teardown); | ||
that.on('data', function(data) { | ||
@@ -102,3 +110,3 @@ progress = data.progress; | ||
update(); | ||
callback(); | ||
}); | ||
@@ -147,4 +155,4 @@ }; | ||
}; | ||
var teardown = function() { | ||
var callback = that._teardown || function(_, fn) { | ||
var teardown = function(callback) { | ||
var teardownCallback = that._teardown || function(_, fn) { | ||
fn(); | ||
@@ -161,9 +169,19 @@ }; | ||
callback(stats, function(err) { | ||
teardownCallback(stats, function(err) { | ||
if(err) { | ||
return that.emit('error', err); | ||
return callback(err); | ||
} | ||
applicationDb.close(); | ||
logDb && logDb.close(); | ||
async.parallel([ | ||
function(next) { | ||
applicationDb.close(next); | ||
}, | ||
function(next) { | ||
if(!logDb) { | ||
return next(); | ||
} | ||
logDb.close(next); | ||
} | ||
], callback); | ||
}); | ||
@@ -173,4 +191,11 @@ }; | ||
patch(that); | ||
setup(); | ||
setup(function(err) { | ||
if(err) { | ||
return that.emit('error', err); | ||
} | ||
update(); | ||
}); | ||
return that; | ||
@@ -177,0 +202,0 @@ }; |
243367
783