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

Method _sendFile

modules/pm2-io-agent/src/push/PushInteractor.js:176–205  ·  view source on GitHub ↗

* Handle packet containing file metadata to send to KM

(packet)

Source from the content-addressed store, hash-verified

174 * Handle packet containing file metadata to send to KM
175 */
176 _sendFile (packet) {
177 const filePath = JSON.parse(JSON.stringify(packet.data.return.dump_file))
178 let type = null
179 if (packet.data.return.heapdump) {
180 type = 'heapdump'
181 } else if (packet.data.return.heapprofile) {
182 type = 'heapprofile'
183 } else if (packet.data.return.cpuprofile) {
184 type = 'cpuprofile'
185 } else {
186 return debug(`Invalid profiling packet: ${JSON.stringify(packet)}`)
187 }
188 debug('Send file for %s', type)
189
190 packet = {
191 pm_id: packet.process.pm_id,
192 name: packet.process.name,
193 server_name: this.opts.MACHINE_NAME,
194 public_key: this.opts.PUBLIC_KEY,
195 type: type
196 }
197 packet[type] = true
198
199 fs.readFile(filePath, (err, data) => {
200 if (err) return debug(err)
201 fs.unlink(filePath, debug)
202 packet.data = data.toString('utf-8')
203 return this.transport.send('profiling', packet)
204 })
205 }
206}

Callers 2

_onPM2EventMethod · 0.95

Calls 3

toStringMethod · 0.80
sendMethod · 0.65
parseMethod · 0.45

Tested by

no test coverage detected