mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-12 19:49:59 +05:00
Improve tools for monitoring plugin
This commit is contained in:
parent
e7f3816445
commit
7a9cb07bb8
@ -797,6 +797,19 @@ COMMANDS.VALIDATE_LOGIN_BLOCK = function (data, cb) {
|
||||
Block.validateLoginBlock(Env, data.publicKey, data.signature, data.block, cb);
|
||||
};
|
||||
|
||||
Object.keys(plugins || {}).forEach(name => {
|
||||
let plugin = plugins[name];
|
||||
if (!plugin.addWorkerCommands) { return; }
|
||||
try {
|
||||
let events = plugin.addWorkerCommands(Env);
|
||||
Object.keys(events || {}).forEach(cmd => {
|
||||
if (typeof(events[cmd]) !== "function") { return; }
|
||||
if (COMMANDS[cmd]) { return; }
|
||||
COMMANDS[cmd] = events[cmd];
|
||||
});
|
||||
} catch (e) {}
|
||||
});
|
||||
|
||||
process.on('message', function (data) {
|
||||
if (!data || !data.txid || !data.pid) {
|
||||
return void process.send({
|
||||
@ -805,6 +818,13 @@ process.on('message', function (data) {
|
||||
});
|
||||
}
|
||||
|
||||
const command = COMMANDS[data.command];
|
||||
|
||||
// Command broadcasted to all workers: no callback expected
|
||||
if (data.type === 'broadcast') {
|
||||
return void command(data);
|
||||
}
|
||||
|
||||
const cb = function (err, value) {
|
||||
process.send({
|
||||
error: Util.serializeError(err),
|
||||
@ -822,7 +842,6 @@ process.on('message', function (data) {
|
||||
});
|
||||
}
|
||||
|
||||
const command = COMMANDS[data.command];
|
||||
if (typeof(command) !== 'function') {
|
||||
return void cb("E_BAD_COMMAND");
|
||||
}
|
||||
|
||||
@ -315,6 +315,18 @@ Workers.initialize = function (Env, config, _cb) {
|
||||
}));
|
||||
});
|
||||
}).nThen(function () {
|
||||
Env.broadcastWorkerCommand = (data) => {
|
||||
workers.forEach(state => {
|
||||
state.worker.send({
|
||||
type: 'broadcast',
|
||||
pid: PID,
|
||||
command: data.command,
|
||||
txid: data.txid
|
||||
});
|
||||
});
|
||||
return workers;
|
||||
};
|
||||
|
||||
Env.computeIndex = function (Env, channel, cb) {
|
||||
Env.store.getWeakLock(channel, function (next) {
|
||||
sendCommand({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user