MCPcopy
hub / github.com/Unitech/pm2 / launchRPC

Method launchRPC

modules/pm2-io-agent/src/InteractorClient.js:113–159  ·  view source on GitHub ↗

* Start a RPC client that connect to the InteractorDaemon * @param {Object} conf global constants * @param {Function} cb invoked with

(conf, cb)

Source from the content-addressed store, hash-verified

111 * @param {Function} cb invoked with <err>
112 */
113 static launchRPC (conf, cb) {
114 const req = axon.socket('req')
115 this.rpc = {}
116 this.client = new rpc.Client(req)
117
118 log('Generating Interactor methods of RPC client')
119
120 // attach known methods to RPC client
121 const generateMethods = (cb) => {
122 this.client.methods((err, methods) => {
123 if (err) return cb(err)
124 Object.keys(methods).forEach((key) => {
125 let method = methods[key]
126 log('+ Adding %s method to interactor RPC client', method.name);
127 ((name) => {
128 let self = this
129 this.rpc[name] = function () {
130 let args = Array.prototype.slice.call(arguments)
131 args.unshift(name)
132 self.client.call.apply(self.client, args)
133 }
134 })(method.name)
135 })
136 return cb()
137 })
138 }
139
140 this.client.sock.once('reconnect attempt', (err) => {
141 this.client.sock.removeAllListeners()
142 return cb(err, { success: false, msg: 'reconnect attempt' })
143 })
144
145 this.client.sock.once('error', (err) => {
146 log('-- Error in error catch all on Interactor --', err)
147 return cb(err, { success: false, msg: 'reconnect attempt' })
148 })
149
150 this.client.sock.once('connect', () => {
151 this.client.sock.removeAllListeners()
152 generateMethods(_ => {
153 log('Methods of RPC client for Interaction ready.')
154 return cb(null, { success: true })
155 })
156 })
157
158 this.client_sock = req.connect(conf.INTERACTOR_RPC_PORT)
159 }
160
161 /**
162 * Start or Restart the Interaction Daemon depending if its online or not

Callers 8

killInteractorDaemonMethod · 0.95
launchOrAttachMethod · 0.95
updateMethod · 0.95
getInteractInfoMethod · 0.95
Client.jsFile · 0.80
updateMethod · 0.80
API.jsFile · 0.80

Calls 4

cbFunction · 0.85
onceMethod · 0.65
removeAllListenersMethod · 0.65
connectMethod · 0.65

Tested by

no test coverage detected