mm_monitor 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/config.json +14 -2
  2. package/index.js +17 -8
  3. package/package.json +1 -1
package/config.json CHANGED
@@ -29,7 +29,19 @@
29
29
  // "phone": "",
30
30
  // // 推送的内容
31
31
  // "content": "服务器异常,请尽快进行维护!--考勤系统"
32
- // }
32
+ // },
33
+ {
34
+ // 网站名称
35
+ "name": "考勤系统",
36
+ // URL地址
37
+ "url": "https://faces.aieliantong.com/api/face/project?size=1",
38
+ // 推送到邮箱
39
+ "email": "573242395@qq.com",
40
+ // 发送短信到
41
+ "phone": "15817188815",
42
+ // 推送的内容
43
+ "content": "服务器异常,请尽快进行维护!--考勤系统"
44
+ }
33
45
  ],
34
- "interval": 3
46
+ "interval": 30
35
47
  }
package/index.js CHANGED
@@ -48,7 +48,8 @@ class Monitor {
48
48
  interval: 30,
49
49
  interval_again: 3600
50
50
  }
51
-
51
+ // 是否已发送,用于避免重复发送
52
+ this.sended = false;
52
53
  this.init(config);
53
54
  }
54
55
  }
@@ -103,9 +104,16 @@ Monitor.prototype.loop = async function() {
103
104
  try {
104
105
  var bl = await this.checkServer(o.url);
105
106
  if (!bl) {
106
- console.log("发生异常", (new Date()).toStr('yyyy-MM-dd hh:mm:ss'), o);
107
- await this.notiy(o);
108
- hasBug = true;
107
+ $.sleep(1000);
108
+ bl = await this.checkServer(o.url);
109
+ if (!bl) {
110
+ console.log("发生异常", (new Date()).toStr('yyyy-MM-dd hh:mm:ss'), o);
111
+ if (!this.sended) {
112
+ this.sended = true;
113
+ await this.notiy(o);
114
+ hasBug = true;
115
+ }
116
+ }
109
117
  }
110
118
  } catch (err) {
111
119
  console.error(err);
@@ -116,8 +124,8 @@ Monitor.prototype.loop = async function() {
116
124
  // 如果出现异常,则先暂停运行
117
125
  clearInterval(this.timer);
118
126
  // 等过了N久后再运行,避免连续通知
119
- setTimeout(() => {
120
- this.run();
127
+ setTimeout(async () => {
128
+ await this.run();
121
129
  }, this.config.interval_again * 1000);
122
130
  }
123
131
  }
@@ -126,8 +134,9 @@ Monitor.prototype.loop = async function() {
126
134
  * 运行监听
127
135
  */
128
136
  Monitor.prototype.run = async function() {
129
- this.timer = setInterval(() => {
130
- this.loop();
137
+ this.sended = false;
138
+ this.timer = setInterval(async () => {
139
+ await this.loop();
131
140
  }, this.config.interval * 1000);
132
141
  }
133
142
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_monitor",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "超级美眉监听器,用于监听网站运行是否异常并给运维人员发短信、邮箱通知",
5
5
  "main": "index.js",
6
6
  "scripts": {