用node.js做cluster,监听异常的邮件提醒服务
__ __ __ _ __
____ ____ ____/ /__ _____/ /_ _______/ /____ _____ ___ ____ ___ ____ _(_) /
/ __ \/ __ \/ __ / _ \______/ ___/ / / / / ___/ __/ _ \/ ___/_____/ _ \/ __ `__ \/ __ `/ / /
/ / / / /_/ / /_/ / __/_____/ /__/ / /_/ (__ ) /_/ __/ / /_____/ __/ / / / / / /_/ / / /
/_/ /_/\____/\__,_/\___/ \___/_/\__,_/____/\__/\___/_/ \___/_/ /_/ /_/\__,_/_/_/
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:
fromsender emailtimeoutsendmail timeout in millisecondssubjectdefaulting to "cluster({worker}) exception: {message}"templatefunction called with local variables (usually jade / ejs template etc)
Example
const cluster = require('cluster')
const cpu = require ('os').cpus().length
const 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
用node.js做cluster,监听异常的邮件提醒服务的更多相关文章
- Node.js之事件监听和发送
演示事件的发送和监听 const events = require("events"); function Account() { this.balance = 0; events ...
- JS通用事件监听函数
JS通用事件监听函数 版本一 //把它全部封装到一个对象中 var obj={ readyEvent:function (fn){ if(fn==null){ fn=document; } var o ...
- Oracle 监听器日志文件过大导致监听异常
Oracle 监听器日志文件过大导致监听异常 db版本:11.2.0.1 os版本:windows2008 现象: 应用异常,无法连接数据库.登陆数据库服务器,查看监听已经断掉.尝试重启监听,重启失败 ...
- 简单剖析Node中的事件监听机制(一)
使用js的class类简单的实现一个事件监听机制,不同于浏览器中的时间绑定与监听,类似于node中的时间监听,并且会在接下来的文章中去根据自己的理解去写一下Event模块中的原理. Node.js使用 ...
- js进阶 12-6 监听鼠标滚动事件和窗口改变事件怎么写
js进阶 12-6 监听鼠标滚动事件和窗口改变事件怎么写 一.总结 一句话总结:滚动事件scroll(),浏览器窗口调整监听resize(),思考好监听对象. 1.滚动事件scroll()的监听对象是 ...
- js添加事件监听的方式与this
js添加事件监听与this js添加事件监听的方式与this 在标签中调用自定义函数 DOM0级事件处理程序 DOM2级事件处理程序 this 代表谁? js添加事件监听的方式与this <di ...
- Node.js的cluster模块——Web后端多进程服务
众所周知,Node.js是单线程的,一个单独的Node.js进程无法充分利用多核.Node.js从v0.6.0开始,新增cluster模块,让Node.js开发Web服务时,很方便的做到充分利用多核机 ...
- node.js使用cluster实现多进程
首先郑重声明: nodeJS 是一门单线程!异步!非阻塞语言! nodeJS 是一门单线程!异步!非阻塞语言! nodeJS 是一门单线程!异步!非阻塞语言! 重要的事情说3遍. 因为nodeJS天生 ...
- 初涉node.js做微信测试公众号一路填坑顺便发现个有趣的其他漏洞
[微信测试公众号] 半年前耍着玩搭起来的“微信简历”,是LAMP版的,很皮毛. 微信的官方文档在这 http://mp.weixin.qq.com/wiki/index.php 1.获取access ...
随机推荐
- 《Spring_Four》第一次作业:团队亮相
part one: 1.队名:Spring_Four 2.团队成员组成:学号/姓名(标记团队组长) 201571030114 李蕾 201571030143 周甜甜 201571030139 张天旭( ...
- cmake find_package 中,include_directories,target_link_libraries 的值怎么知道?
拿Sophus库为例: find_package(Sophus REQUIRED) include_directories(${Sophus_INCLUDE_DIRS}) target_link_li ...
- 在IDEA中停止和关闭SonarLint自动检查,手动运行SonarLint检查代码
关闭SonarLint自动检查代码 有时敲一行代码SonarLint插件就会自动检查,让人感觉很不舒服,还会使电脑卡顿: 依次点击:File -> Settings 或直接Ctrl+Alt+S ...
- Git 分支合并:合并某次提交
有时只想合并其它分支到某次提交,而不是所有提交. 一 切换到当前分支 首先,在做一次可能有冲突的合并前尽可能保证工作目录是干净的. 如果你有正在做的工作,要么提交到一个临时分支要么储藏它. 这使你可以 ...
- HDU 5828 Rikka with Sequence(线段树区间加开根求和)
Problem DescriptionAs we know, Rikka is poor at math. Yuta is worrying about this situation, so he g ...
- github windows配置以及ssh生成 Permission denied (publickey)
1:进入cmd命令下,或者可以使用GIt工具 (如果出现了 Permission denied 或者配置多个SSH Key跳第6步) git工具 下载地址:https://git-scm.com ...
- Android 记录点滴
1:关于断点 设置断点点三角是进不去的,这个是类似c#的release 正式版, 点第二个红圈内的debug的那个按钮才可以 . 这个按钮可以让程序及时进入当前断点处 2:对于背景颜色 andro ...
- tornado框架学习及借用有道翻译api做自动翻译页面
趁着这几天有时间,就简单的学了一下tornado框架,简单做了个自动翻译的页面 仅为自己学习参考,不作其他用途 文件夹目录结构如下: . ├── server.py ├── static │ └─ ...
- Scanner 随机数
import java.util.Scanner; import java.util.Scanner; Sc ...
- 设计模式学习心得<工厂方法 Factory Method>
概述 意图 业务代码中常常有构造对象的过程,它拥有大量的参数.并且有很多地方需要这对象. 简化对象构造过程. 主要解决 一个类在不同场景的频繁地创建,让不同对象的创建更有语义化,提高代码复用性. 何时 ...