From 32417bc8a41bff2c1e6b617e46344d53a3d9cd4a Mon Sep 17 00:00:00 2001 From: XadillaX Date: Fri, 28 Jul 2017 18:42:59 +0800 Subject: [PATCH] cluster, logger: support for akyuu.startCluster() Add the dependency of akyuu-cluster and make logger to adapt cluster. PR-URL: https://github.com/akyuujs/akyuu/pull/28 Refs: https://github.com/eggjs/egg-cluster#usage Reviewed-By: Duan Pengfei --- example/demo/src/config/default/index.js | 6 ++++++ example/demo/src/master.js | 10 ++++++++++ index.js | 2 ++ lib/logger/index.js | 1 + package.json | 1 + 5 files changed, 20 insertions(+) create mode 100644 example/demo/src/master.js diff --git a/example/demo/src/config/default/index.js b/example/demo/src/config/default/index.js index 23b32ee..1084065 100644 --- a/example/demo/src/config/default/index.js +++ b/example/demo/src/config/default/index.js @@ -15,6 +15,12 @@ module.exports = { autoStatusCode: true }, + cluster: { + workerCount: 2, + entry: path.join(__dirname, "../../app.js"), + limit: 2 + }, + test: { test1: true }, diff --git a/example/demo/src/master.js b/example/demo/src/master.js new file mode 100644 index 0000000..1f4058b --- /dev/null +++ b/example/demo/src/master.js @@ -0,0 +1,10 @@ +/** + * XadillaX created at 2017-07-28 15:32:46 with ❤ + * + * Copyright (c) 2017 xcoder.in, all rights reserved. + */ +"use strict"; + +const akyuu = require("../../../"); + +akyuu.startCluster(); diff --git a/index.js b/index.js index 3ecf3c3..a118953 100644 --- a/index.js +++ b/index.js @@ -17,3 +17,5 @@ akyuu.Validator = require("joi"); akyuu.Service = require("./lib/requester"); module.exports = akyuu; + +akyuu.startCluster = require("akyuu-cluster").startCluster.bind(akyuu, __dirname); diff --git a/lib/logger/index.js b/lib/logger/index.js index 9207a7a..fd4aa7c 100644 --- a/lib/logger/index.js +++ b/lib/logger/index.js @@ -54,6 +54,7 @@ class Logger { }; for(let i = 0; i < this.transportConfig.length; i++) { + if(this.transportConfig[i].enabled === false) continue; const type = _.startCase(this.transportConfig[i].type); const transportOption = Object.assign({}, this.transportConfig[i], { timestamp: _timestamp, diff --git a/package.json b/package.json index 7c8705f..579574c 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ }, "homepage": "https://github.com/akyuujs/akyuu#readme", "dependencies": { + "akyuu-cluster": "^1.0.0", "async": "^2.1.5", "case": "^1.5.2", "config": "^1.20.1",