1 | const fs = require('fs');
|
2 | const forEachLimit = require('async/forEachLimit');
|
3 |
|
4 | var cst = require('../../../constants.js');
|
5 | var Common = require('../../Common.js');
|
6 |
|
7 | module.exports = function(CLI) {
|
8 | |
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | CLI.prototype.monitorState = function(state, target, cb) {
|
15 | var that = this;
|
16 |
|
17 | if (!target) {
|
18 | Common.printError(cst.PREFIX_MSG_ERR + 'Please specify an <app_name|pm_id>');
|
19 | return cb ? cb(new Error('argument missing')) : that.exitCli(cst.ERROR_EXIT);
|
20 | }
|
21 |
|
22 | function monitor (pm_id, cb) {
|
23 |
|
24 | that.Client.executeRemote(state, pm_id, cb);
|
25 | }
|
26 | if (target === 'all') {
|
27 | that.Client.getAllProcessId(function (err, procs) {
|
28 | if (err) {
|
29 | Common.printError(err);
|
30 | return cb ? cb(Common.retErr(err)) : that.exitCli(cst.ERROR_EXIT);
|
31 | }
|
32 | forEachLimit(procs, 1, monitor, function (err, res) {
|
33 | return typeof cb === 'function' ? cb(err, res) : that.speedList();
|
34 | });
|
35 | });
|
36 | } else if (!Number.isInteger(parseInt(target))) {
|
37 | this.Client.getProcessIdByName(target, true, function (err, procs) {
|
38 | if (err) {
|
39 | Common.printError(err);
|
40 | return cb ? cb(Common.retErr(err)) : that.exitCli(cst.ERROR_EXIT);
|
41 | }
|
42 | forEachLimit(procs, 1, monitor, function (err, res) {
|
43 | return typeof cb === 'function' ? cb(err, res) : that.speedList();
|
44 | });
|
45 | });
|
46 | } else {
|
47 | monitor(parseInt(target), function (err, res) {
|
48 | return typeof cb === 'function' ? cb(err, res) : that.speedList();
|
49 | });
|
50 | }
|
51 | };
|
52 | }
|