mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
problem pretest
This commit is contained in:
1 parent
dd5a212422
commit
554698189c
17 files changed
+127
-57
No files matched your search
+9
-19
@@ -1,5 +1,4 @@
|
||||
const { EventEmitter } = require('events');
|
||||
const cluster = require('cluster');
|
||||
|
||||
const bus = new EventEmitter();
|
||||
|
||||
@@ -26,27 +25,18 @@ function unsubscribe(events, handler, funcName) {
|
||||
}
|
||||
}
|
||||
|
||||
function publish(event, data, isMaster = true) {
|
||||
bus.emit(event, { value: data, event });
|
||||
if (isMaster && global.Hydro.model.task) {
|
||||
global.Hydro.model.task.add({
|
||||
type: 'bus',
|
||||
count: Object.keys(cluster.workers).length,
|
||||
sender: cluster.worker.id,
|
||||
event,
|
||||
data,
|
||||
function publish(event, payload, isMaster = true) {
|
||||
if (isMaster && process.send) {
|
||||
process.send({
|
||||
event: 'bus',
|
||||
eventName: event,
|
||||
payload,
|
||||
});
|
||||
} else {
|
||||
bus.emit(event, { value: payload, event });
|
||||
}
|
||||
}
|
||||
|
||||
function postInit() {
|
||||
const { task } = global.Hydro.model;
|
||||
task.consume({ type: 'bus' }, (data) => {
|
||||
if (data.sender === cluster.worker.id) return;
|
||||
publish(data.event, data.value, false);
|
||||
});
|
||||
}
|
||||
|
||||
global.Hydro.service.bus = module.exports = {
|
||||
subscribe, unsubscribe, publish, postInit,
|
||||
subscribe, unsubscribe, publish,
|
||||
};
|
||||
@@ -297,7 +297,7 @@ class Handler {
|
||||
this.ctx.response.status = 302;
|
||||
this.ctx.redirect(this.response.redirect);
|
||||
} else {
|
||||
if (this.response.body.redirect) {
|
||||
if (this.response.redirect) {
|
||||
this.response.body = this.response.body || {};
|
||||
this.response.body.url = this.response.redirect;
|
||||
}
|
||||
@@ -438,6 +438,7 @@ class ConnectionHandler {
|
||||
if (anchor) return `${res}#${anchor}`;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
console.error(name, kwargs);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user