Event.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Copyright 2013-2022 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. var Utility = require('./Utility.js');
  7. module.exports = function(God) {
  8. God.notify = function(action_name, data, manually) {
  9. God.bus.emit('process:event', {
  10. event : action_name,
  11. manually : typeof(manually) == 'undefined' ? false : true,
  12. process : Utility.formatCLU(data),
  13. at : Utility.getDate()
  14. });
  15. };
  16. God.notifyByProcessId = function(opts, cb) {
  17. if (typeof(opts.id) === 'undefined') { return cb(new Error('process id missing')); }
  18. var proc = God.clusters_db[opts.id];
  19. if (!proc) { return cb(new Error('process id doesnt exists')); }
  20. God.bus.emit('process:event', {
  21. event : opts.action_name,
  22. manually : typeof(opts.manually) == 'undefined' ? false : true,
  23. process : Utility.formatCLU(proc),
  24. at : Utility.getDate()
  25. });
  26. process.nextTick(function() {
  27. return cb ? cb(null) : false;
  28. });
  29. return false;
  30. };
  31. };