MCPcopy Create free account
hub / github.com/desaroger/pm2-hooks / _parseProcess

Method _parseProcess

src/Pm2Module.js:83–128  ·  view source on GitHub ↗

* Converts a PM2 process object to an object for WebhookServer * route. * * Example 1: * - input: { pm2_env: { env_hook: { name: 'api', type: 'bitbucket' } } } * - output: { name: 'api', type: 'bitbucket' } * Example 2: * - input: { pm2_env: { env_hook: { type: 'bi

(app)

Source from the content-addressed store, hash-verified

81 * @private
82 */
83 static _parseProcess(app) {
84 // Check data
85 if (!app || !app.pm2_env) {
86 return null;
87 }
88 let config = app.pm2_env.env_hook;
89 if (!config) {
90 log(`No options found for "${app.name}" route`);
91 return null;
92 }
93 if (config === true) {
94 config = {};
95 }
96
97 // Config to WebhookServer route
98 let self = this;
99 let name = app.name || 'unknown';
100 let cwd = config.cwd || app.pm_cwd || app.pm2_env.cwd || app.pm2_env.pm_cwd;
101 let commandOptions = Object.assign({}, { cwd }, config.commandOptions || {});
102 let route = {
103 name,
104 type: config.type,
105 secret: config.secret,
106 method(payload) {
107 log(`Parsed payload: ${JSON.stringify(payload)}`);
108 try {
109 if (config.command) {
110 log(`Running command: ${config.command}`);
111 self._runCommand(config.command, commandOptions)
112 .catch(e => onError(name, e));
113 }
114 } catch (e) {
115 onError(name, e);
116 }
117 }
118 };
119 route = cleanObj(route);
120
121 return route;
122
123 function onError(routeName, e) {
124 let err = e.message || e;
125 log(`Error on "${name}" route: ${err}`, 2);
126 throw e;
127 }
128 }
129
130 /**
131 * Runs a line command.

Callers 2

Pm2Module.jsFile · 0.80
_parseProcessesMethod · 0.80

Calls 2

logFunction · 0.85
cleanObjFunction · 0.85

Tested by

no test coverage detected