Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
fix(sync_worker): make sure end event will emit
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Nov 6, 2014
1 parent 651d4b2 commit aa9d647
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions controllers/sync_module_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,19 @@ SyncModuleWorker.prototype.start = function () {
co(function *() {
// sync upstream
if (config.sourceNpmRegistryIsCNpm) {
yield* that.syncUpstream(that.startName);
try {
yield* that.syncUpstream(that.startName);
} catch (err) {
logger.error(err);
}
}

var arr = [];
for (var i = 0; i < that.concurrency; i++) {
arr.push(that.next(i));
}
yield arr;
})(function (err) {
if (err) {
logger.error(err);
}
});
})();
};

SyncModuleWorker.prototype.pushSuccess = function (name) {
Expand Down
12 changes: 6 additions & 6 deletions sync/sync_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* Module dependencies.
*/

var debug = require('debug')('cnpmjs.org:sync:sync_all');
var ms = require('humanize-ms');
var thunkify = require('thunkify-wrap');
var config = require('../config');
var Status = require('./status');
var npmService = require('../services/npm');
var totalService = require('../services/total');
var SyncModuleWorker = require('../controllers/sync_module_worker');
var logger = require('../common/logger');

/**
* when sync from official at the first time
Expand Down Expand Up @@ -61,20 +61,20 @@ module.exports = function* sync() {
}

var packages;
debug('Last sync time %s', new Date(info.last_sync_time));
logger.syncInfo('Last sync time %s', new Date(info.last_sync_time));
if (!info.last_sync_time) {
debug('First time sync all packages from official registry');
logger.syncInfo('First time sync all packages from official registry');
packages = yield* getFirstSyncPackages(info.last_sync_module);
} else {
packages = yield* getCommonSyncPackages(info.last_sync_time - ms('10m'));
}

packages = packages || [];
if (!packages.length) {
debug('no packages need be sync');
logger.syncInfo('no packages need be sync');
return;
}
debug('Total %d packages to sync', packages.length);
logger.syncInfo('Total %d packages to sync: %j', packages.length, packages);

var worker = new SyncModuleWorker({
username: 'admin',
Expand All @@ -87,7 +87,7 @@ module.exports = function* sync() {
var end = thunkify.event(worker);
yield end();

debug('All packages sync done, successes %d, fails %d',
logger.syncInfo('All packages sync done, successes %d, fails %d',
worker.successes.length, worker.fails.length);
//only when all succss, set last sync time
if (!worker.fails.length) {
Expand Down

0 comments on commit aa9d647

Please sign in to comment.