feat: upgrade to co4
This commit is contained in:
20
Makefile
20
Makefile
@@ -2,12 +2,18 @@ TESTS = $(shell ls -S `find test -type f -name "*.test.js" -print`)
|
||||
REPORTER = spec
|
||||
TIMEOUT = 30000
|
||||
MOCHA_OPTS =
|
||||
REGISTRY = --registry=https://registry.npm.taobao.org
|
||||
DB = sqlite
|
||||
DISTURL = http://npm.taobao.org/mirrors/iojs
|
||||
BIN = iojs
|
||||
|
||||
ifeq ($(findstring io.js, $(shell which node)),)
|
||||
BIN = node
|
||||
DISTURL = http://npm.taobao.org/mirrors/node
|
||||
endif
|
||||
|
||||
install:
|
||||
@npm install --build-from-source $(REGISTRY) \
|
||||
--disturl=https://npm.taobao.org/dist
|
||||
@npm install --build-from-source --registry=http://registry.npm.taobao.org \
|
||||
--disturl=$(DISTURL)
|
||||
|
||||
install-production production:
|
||||
@NODE_ENV=production $(MAKE) install
|
||||
@@ -16,7 +22,7 @@ jshint: install
|
||||
@-node_modules/.bin/jshint ./
|
||||
|
||||
init-database:
|
||||
@node --harmony test/init_db.js
|
||||
@$(BIN) --harmony test/init_db.js
|
||||
|
||||
init-mysql:
|
||||
@mysql -uroot -e 'DROP DATABASE IF EXISTS cnpmjs_test;'
|
||||
@@ -43,7 +49,7 @@ test-mysql: init-mysql
|
||||
test-all: test-sqlite test-mysql
|
||||
|
||||
test-cov cov: install init-database
|
||||
@NODE_ENV=test DB=${DB} node --harmony \
|
||||
@NODE_ENV=test DB=${DB} $(BIN) --harmony \
|
||||
node_modules/.bin/istanbul cover --preserve-comments \
|
||||
node_modules/.bin/_mocha \
|
||||
-- -u exports \
|
||||
@@ -64,7 +70,7 @@ test-cov-mysql: init-mysql
|
||||
|
||||
test-travis: install init-database
|
||||
@NODE_ENV=test DB=${DB} CNPM_SOURCE_NPM=https://registry.npmjs.org CNPM_SOURCE_NPM_ISCNPM=false \
|
||||
node --harmony \
|
||||
$(BIN) --harmony \
|
||||
node_modules/.bin/istanbul cover --preserve-comments \
|
||||
node_modules/.bin/_mocha \
|
||||
--report lcovonly \
|
||||
@@ -87,7 +93,7 @@ test-travis-mysql: init-mysql
|
||||
test-travis-all: test-travis-sqlite test-travis-mysql
|
||||
|
||||
dev:
|
||||
@NODE_ENV=development node_modules/.bin/node-dev --harmony dispatch.js
|
||||
@NODE_ENV=development $(BIN) node_modules/.bin/node-dev --harmony dispatch.js
|
||||
|
||||
contributors: install
|
||||
@node_modules/.bin/contributors -f plain -o AUTHORS
|
||||
|
||||
@@ -116,10 +116,13 @@ SyncModuleWorker.prototype._saveLog = function () {
|
||||
that._log = '';
|
||||
co(function* () {
|
||||
yield* logService.append(that._logId, logstr);
|
||||
})(function (err) {
|
||||
if (err) {
|
||||
logger.error(err);
|
||||
}).then(function () {
|
||||
that._loging = false;
|
||||
if (that._log) {
|
||||
that._saveLog();
|
||||
}
|
||||
}).catch(function (err) {
|
||||
logger.error(err);
|
||||
that._loging = false;
|
||||
if (that._log) {
|
||||
that._saveLog();
|
||||
@@ -131,7 +134,7 @@ SyncModuleWorker.prototype.start = function () {
|
||||
this.log('user: %s, sync %s worker start, %d concurrency, nodeps: %s, publish: %s',
|
||||
this.username, this.names[0], this.concurrency, this.noDep, this._publish);
|
||||
var that = this;
|
||||
co(function *() {
|
||||
co(function* () {
|
||||
// sync upstream
|
||||
if (that.syncUpstreamFirst) {
|
||||
try {
|
||||
@@ -151,7 +154,9 @@ SyncModuleWorker.prototype.start = function () {
|
||||
arr.push(that.next(i));
|
||||
}
|
||||
yield arr;
|
||||
})();
|
||||
}).catch(function (err) {
|
||||
logger.error(err);
|
||||
});
|
||||
};
|
||||
|
||||
SyncModuleWorker.prototype.pushSuccess = function (name) {
|
||||
|
||||
12
package.json
12
package.json
@@ -14,11 +14,11 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"agentkeepalive": "~1.2.0",
|
||||
"bluebird": "~2.9.6",
|
||||
"bluebird": "~2.9.7",
|
||||
"bytes": "~1.0.0",
|
||||
"cfork": "~1.2.2",
|
||||
"co": "~3.1.0",
|
||||
"co-defer": "~0.1.2",
|
||||
"co": "~4.3.1",
|
||||
"co-defer": "~1.0.0",
|
||||
"co-gather": "~0.0.1",
|
||||
"co-sleep": "~0.0.1",
|
||||
"commander": "~2.6.0",
|
||||
@@ -33,13 +33,13 @@
|
||||
"humanize-ms": "~1.0.1",
|
||||
"humanize-number": "~0.0.2",
|
||||
"kcors": "~1.0.0",
|
||||
"koa": "~0.13.0",
|
||||
"koa": "~0.17.0",
|
||||
"koa-limit": "~1.0.2",
|
||||
"koa-markdown": "~2.0.1",
|
||||
"koa-middlewares": "~2.1.0",
|
||||
"koa-mock": "~1.1.4",
|
||||
"markdown-it": "~3.0.4",
|
||||
"mime": "~1.2.11",
|
||||
"markdown-it": "~3.0.5",
|
||||
"mime": "~1.3.4",
|
||||
"mini-logger": "~1.0.0",
|
||||
"mkdirp": "~0.5.0",
|
||||
"moment": "~2.9.0",
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
global.Promise = require('bluebird');
|
||||
var koa = require('koa');
|
||||
var app = module.exports = koa();
|
||||
var http = require('http');
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
global.Promise = require('bluebird');
|
||||
var opensearch = require('../middleware/opensearch');
|
||||
var notFound = require('../middleware/web_not_found');
|
||||
var staticCache = require('../middleware/static');
|
||||
|
||||
@@ -28,6 +28,7 @@ function* request(url, options) {
|
||||
'user-agent': USER_AGENT
|
||||
};
|
||||
options.gzip = true;
|
||||
options.followRedirect = true;
|
||||
var registry = options.registry || config.sourceNpmRegistry;
|
||||
url = registry + url;
|
||||
var r;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
global.Promise = require('bluebird');
|
||||
var debug = require('debug')('cnpmjs.org:sync:index');
|
||||
var co = require('co');
|
||||
var ms = require('humanize-ms');
|
||||
@@ -42,14 +43,14 @@ if (!sync && config.enableCluster) {
|
||||
console.log('[%s] [sync_worker:%s] syncing with %s mode',
|
||||
Date(), process.pid, config.syncModel);
|
||||
|
||||
function onerror(err) {
|
||||
logger.error(err);
|
||||
}
|
||||
|
||||
//set sync_status = 0 at first
|
||||
co(function* () {
|
||||
yield* totalService.updateSyncStatus(0);
|
||||
})(function (err) {
|
||||
if (err) {
|
||||
logger.error(err);
|
||||
}
|
||||
});
|
||||
}).catch(onerror);
|
||||
|
||||
var syncInterval = ms(config.syncInterval);
|
||||
var minSyncInterval = ms('5m');
|
||||
@@ -59,7 +60,7 @@ if (!syncInterval || syncInterval < minSyncInterval) {
|
||||
|
||||
// the same time only sync once
|
||||
var syncing = false;
|
||||
var handleSync = co(function* () {
|
||||
var syncFn = co.wrap(function* () {
|
||||
debug('mode: %s, syncing: %s', config.syncModel, syncing);
|
||||
if (!syncing) {
|
||||
syncing = true;
|
||||
@@ -82,8 +83,10 @@ var handleSync = co(function* () {
|
||||
});
|
||||
|
||||
if (sync) {
|
||||
handleSync();
|
||||
setInterval(handleSync, syncInterval);
|
||||
syncFn().catch(onerror);
|
||||
setInterval(function () {
|
||||
syncFn().catch(onerror);
|
||||
}, syncInterval);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +95,7 @@ if (sync) {
|
||||
|
||||
var startSyncPopular = require('./sync_popular');
|
||||
var syncingPopular = false;
|
||||
var syncPopular = co(function* syncPopular() {
|
||||
var syncPopularFn = co.wrap(function* syncPopular() {
|
||||
if (syncingPopular) {
|
||||
return;
|
||||
}
|
||||
@@ -119,8 +122,10 @@ var syncPopular = co(function* syncPopular() {
|
||||
});
|
||||
|
||||
if (config.syncPopular) {
|
||||
syncPopular();
|
||||
setInterval(syncPopular, ms(config.syncPopularInterval));
|
||||
syncPopularFn().catch(onerror);
|
||||
setInterval(function () {
|
||||
syncPopularFn().catch(onerror);
|
||||
}, ms(config.syncPopularInterval));
|
||||
} else {
|
||||
logger.syncInfo('sync popular module disable');
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ Status.prototype.log = function (syncDone) {
|
||||
};
|
||||
co(function* () {
|
||||
yield* Total.updateSyncNum(params);
|
||||
})();
|
||||
}).catch(function () {});
|
||||
};
|
||||
|
||||
Status.prototype.start = function () {
|
||||
|
||||
@@ -105,11 +105,10 @@ co(function* () {
|
||||
yield tasks;
|
||||
}
|
||||
}
|
||||
})(function (err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
throw err;
|
||||
}
|
||||
}).then(function () {
|
||||
console.log('sync done, you can upgrade to 2.x now.');
|
||||
process.exit(0);
|
||||
}).catch(function (err) {
|
||||
console.error(err);
|
||||
throw err;
|
||||
});
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
var graceful = require('graceful');
|
||||
var logger = require('./common/logger');
|
||||
var config = require('./config');
|
||||
var registry = require('./servers/registry');
|
||||
var web = require('./servers/web');
|
||||
var logger = require('./common/logger');
|
||||
var config = require('./config');
|
||||
|
||||
registry.listen(config.registryPort, config.bindingHost);
|
||||
web.listen(config.webPort, config.bindingHost);
|
||||
|
||||
Reference in New Issue
Block a user