_onMessage(message) { if (message && is.string(message.action)) { debug('[%s] got message %s with %j, receiverPid: %s', this.pid, message.action, message.data, message.receiverPid); this.emit(message.action, message.data); } }
process.on('exit', (code) => { if (code === 0) { process.kill(process.pid) } })
describe("Test utils.getNodeID", () => { let os = require("os"); it("should give the computer hostname", () => { expect(utils.getNodeID()).toBe(os.hostname().toLowerCase() + "-" + process.pid); }); });
dumpTiming() { try { const json = this.timing.toJSON(); const rundir = this.config.rundir; const dumpFile = path.join(rundir, `${this.type}_timing_${process.pid}.json`); fs.writeFileSync(dumpFile, CircularJSON.stringify(json, null, 2)); this.timing.clear(); this.timing.disable(); } catch (err) { this.coreLogger.warn(`dumpTiming error: ${err.message}`); } }
signalTraps.map(type => { process.once(type, async () => { try { await admin.disconnect() } finally { process.kill(process.pid, type) } }) })
/** * Send message to all agent and app * @param {String} action - message key * @param {Object} data - message value * @return {Messenger} this */ broadcast(action, data) { debug('[%s] broadcast %s with %j', this.pid, action, data); this.send(action, data, 'app'); this.send(action, data, 'agent'); return this; }
describe('server listening', () => { it('should be listening', async () => { const child = childProcess.exec(`node ${appPath}`); const isOpen = await waitPort({port: PORT}); expect(isOpen).to.be.true; process.kill(child.pid, 'SIGTERM'); }); });
app.messenger.on('egg-ready', () => { app.messenger.on('app-to-agent', function(msg) { console.log('[app] app-to-agent', msg); }); app.messenger.on('agent-to-app', function(msg) { console.log('[app] agent-to-app', msg); }); app.messenger.send('app-to-agent', 'app msg'); app.messenger.send('pid', process.pid); app.messenger.send('ready'); });
_close (callback) { if (this[kProcess] === null) { return callback() } debug('closing pid %d', this[kProcess].pid) this[kProcess].once('exit', () => callback()) this[kProcess].kill() }
function bindings () { const chindings = this[chindingsSym] var chindingsJson = `{${chindings.substr(1)}}` // at least contains ,"pid":7068,"hostname":"myMac" var bindingsFromJson = JSON.parse(chindingsJson) delete bindingsFromJson.pid delete bindingsFromJson.hostname return bindingsFromJson }
app.messenger.on('egg-ready', () => { app.messenger.broadcast('broadcast', { from: 'app', pid: process.pid, }); });
_onMessage(message) { if (message && is.string(message.action)) { debug('[%s] got message %s with %j', this.pid, message.action, message.data); this.emit(message.action, message.data); } }
/** * send message to agent * @param {String} action - message key * @param {Object} data - message value * @return {Messenger} this */ sendToAgent(action, data) { debug('[%s] send %s with %j to all agent', this.pid, action, data); this.send(action, data, 'agent'); return this; }
signalTraps.map(type => { process.once(type, async () => { try { await consumer.disconnect() } finally { process.kill(process.pid, type) } }) })
signalTraps.map(type => { process.once(type, async () => { try { await producer.disconnect() } finally { process.kill(process.pid, type) } }) })