博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用node.js做cluster,监听异常的邮件提醒服务
阅读量:5080 次
发布时间:2019-06-12

本文共 1845 字,大约阅读时间需要 6 分钟。

__                __           __                                       _ __   ____  ____  ____/ /__        _____/ /_  _______/ /____  _____      ___  ____ ___  ____ _(_) /  / __ \/ __ \/ __  / _ \______/ ___/ / / / / ___/ __/ _ \/ ___/_____/ _ \/ __ `__ \/ __ `/ / / / / / / /_/ / /_/ /  __/_____/ /__/ / /_/ (__  ) /_/  __/ /  /_____/  __/ / / / / / /_/ / / //_/ /_/\____/\__,_/\___/      \___/_/\__,_/____/\__/\___/_/         \___/_/ /_/ /_/\__,_/_/_/

A module for taking advantage of the built-in cluster module in node v0.8 and above.send email if cluster exception,you will recieve a detail email about worker exception.

Installation

npm install https://github.com/sunNode/node-cluster-email

Usage

Initialize mail plugin with the given email(s), with the given options.

Options:

  • from sender email
  • timeout sendmail timeout in milliseconds
  • subject defaulting to "cluster({worker}) exception: {message}"
  • template function called with local variables (usually jade / ejs template etc)

Example

const cluster = require('cluster')const cpu = require ('os').cpus().lengthconst mail = require('node-cluster-mail')/** * [if description] * @param  {[type]} cluster.isMaster [description] * @return {[type]}                  [description] */if (cluster.isMaster) {  // Fork workers.  for (let i = 0; i < cpu; i++) {    cluster.fork();  }  cluster.on('exit', function(worker, code, signal) {    mail('phonenix@gmail.com',{'from':'phonenix-test@gmail.com','cc':'phonenix-test2@gmail.com'})    console.log('worker ' + worker.process.pid + ' died');  });  cluster.on('fork', function(worker) {  console.log(`workers: ${worker.id} worker.process.pid :${worker.process.pid}`)});} else {  // Workers can share any TCP connection  // In this service its a restify server  require('./app')}

Reference

转载于:https://www.cnblogs.com/jacksundatashare/p/6193166.html

你可能感兴趣的文章
播放背景音乐
查看>>
Android 中关于draw中图片分辨率的说明
查看>>
数据库备份启用加密
查看>>
直线运动
查看>>
理解HTTP session原理及应用(转)
查看>>
phpstorm调试环境XDebug搭建
查看>>
PyNest——part 4: topologically structured networks
查看>>
android4.0 jni Hello World 开发~图解
查看>>
SQL实例整理
查看>>
说说记录
查看>>
python入门-数据类型
查看>>
ethtool命令介绍
查看>>
[leetcode]DP动态规划题目整理 [编辑中]
查看>>
[Lydsy1805月赛] 对称数
查看>>
ppt制作教程(1)
查看>>
P1631 序列合并 堆
查看>>
51nod 1273 旅行计划(思维题)
查看>>
Easyui入门视频教程 第05集---Easyui复杂布局
查看>>
recovery PITR 即时恢复
查看>>
页面嵌套 Iframe 产生缓存导致页面数据不刷新问题
查看>>