UNPKG

1.12 kBJavaScriptView Raw
1/**
2 * Copyright 2013-2021 the PM2 project authors. All rights reserved.
3 * Use of this source code is governed by a license that
4 * can be found in the LICENSE file.
5 */
6
7var Utility = require('./Utility.js');
8
9module.exports = function(God) {
10
11 God.notify = function(action_name, data, manually) {
12 God.bus.emit('process:event', {
13 event : action_name,
14 manually : typeof(manually) == 'undefined' ? false : true,
15 process : Utility.formatCLU(data),
16 at : Utility.getDate()
17 });
18 };
19
20 God.notifyByProcessId = function(opts, cb) {
21 if (typeof(opts.id) === 'undefined') { return cb(new Error('process id missing')); }
22 var proc = God.clusters_db[opts.id];
23 if (!proc) { return cb(new Error('process id doesnt exists')); }
24
25 God.bus.emit('process:event', {
26 event : opts.action_name,
27 manually : typeof(opts.manually) == 'undefined' ? false : true,
28 process : Utility.formatCLU(proc),
29 at : Utility.getDate()
30 });
31
32 process.nextTick(function() {
33 return cb ? cb(null) : false;
34 });
35 return false;
36 };
37};