Skip to content

Commit

Permalink
fixbug
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchonghua committed May 24, 2017
1 parent 500aa7e commit d689674
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
14 changes: 7 additions & 7 deletions lib/master/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,8 @@ master.on('worker::event::callWorkerRes', function callWorkerRes (res, handle, w
// /**************************** 子进程对管理进程调用开始 ****************************/
// 子进程中转-转发子进程数据到子进程
master.on('worker::event::workerSendToWorker', function workerSendToWorker (body, handle, worker) {
master.sendToWorker(body.toWorkerId, body.type, body.message, (state, message) => {
master.sendToWorker(worker.id, 'workerSendToWorkerCallback', {
id: body.id,
state: state,
message: message
}).catch(e => master.logError(e))
}).then(({isCallback, state, message, handle}) => {
master.sendToWorker(body.toWorkerId, body.type, body.message)
.then(({isCallback, state, message, handle}) => {
master.sendToWorker(worker.id, 'workerSendToWorkerCallback', {id: body.id, message, isCallback: true}, handle).catch(e => master.logError(e))
}, ({name, type, stack, handle}) => {
master.sendToWorker(worker.id, 'workerSendToWorkerCallback', {id: body.id, errorName: name, errorType: type, errorStack: stack, isCallback: true}, handle).catch(e => master.logError(e))
Expand Down Expand Up @@ -417,6 +412,11 @@ master.on('worker::event::callMaster', (res, handle, worker) => {
// 绑定 daemon 进程发来的信息
process.on('message', function (res, handle) {
if (!res) return
console.log(
typeof (res.isCallback === true && res.id && processCallback && processCallback[res.id]),
res.isCallback, res.id

)
if (res.type && res.id) {
if (master.emit(('daemon::event::' + res.type), res.message, handle)) {
process.send({
Expand Down
4 changes: 3 additions & 1 deletion lib/master/sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ sys.onWorker.message = function (res, handle) {
if (!res) return
if (res.type && res.id) {
if (master.emit(('worker::event::' + res.type), res.message, handle, this)) {
if (res.type === 'workerSendToWorker') {
return
}
this.send({
isCallback: true,
id: res.id,
Expand Down Expand Up @@ -264,4 +267,3 @@ master.serverRun = function masterServerRun () {
require('./server.js')
// 通过守护进程初始化
sys.initByDaemon()

25 changes: 21 additions & 4 deletions lib/worker/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,27 @@ worker.on('master::event::callMasterRes', function callMasterRes (res, handle) {
res = handle = void 0
})
// 管理进程发来信息,是worker发送结果的回调
worker.on('master::event::workerSendToWorkerCallback', function workerSendToWorkerCallback (res) {
if (processCallback && processCallback[res.id] && util.isFunction(processCallback[res.id])) {
processCallback[res.id]((res.state || false), (res.message || 'unknown_error'))
delete processCallback[res.id]
worker.on('master::event::workerSendToWorkerCallback', function workerSendToWorkerCallback (res, handle) {
if (res.isCallback && processCallback && processCallback[res.id]) {
if (res.errorStack) {
if (util.isFunction(processCallback[res.id][1])) {
let e = new worker.WorkerError(res.message || 'worker call worker fail')
e.stack = (res.errorStack || '') + '\n\n' + e.stack
e.type = res.errorType || 'sendToWorker'
e.name = res.errorName || 'WORKER_CALL_WORKER_FAIL'
e.id = res.id
e.handle = handle
processCallback[res.id][1].call(processCallback[res.id][2], e)
}
} else {
if (util.isFunction(processCallback[res.id][0])) {
processCallback[res.id][0].call(processCallback[res.id][2], {
id: res.id,
message: res.message,
handle
})
}
}
}
})

Expand Down

0 comments on commit d689674

Please sign in to comment.