amqplib-init 1.1.4 → 1.1.6

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 (2) hide show
  1. package/index.js +21 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -17,13 +17,15 @@ module.exports = {
17
17
  const {
18
18
  channelName = 'node-test-channel',
19
19
  prefetch = 1,
20
- callback = ()=> {},
21
20
  pmId = 0,
21
+ callback = ()=> {},
22
22
  finish = ()=> {},
23
23
  amqpLink = ``,
24
24
  heartbeat = 5,
25
25
  timeout = 120000,
26
26
  delay = 0,
27
+ autoReload = 0,
28
+ queryHook = () => {},
27
29
  init = () => {}
28
30
  } = option;
29
31
  const durable = true;
@@ -93,6 +95,24 @@ module.exports = {
93
95
  amqpInit(true);
94
96
  });
95
97
  chalk.log(`✳️-队列已启动: finish~`);
98
+ if (autoReload > 0) {
99
+ console.log(`❤️ 将在 ${autoReload}ms 秒后自动重启!!!`)
100
+ setInterval(async _=> {
101
+ try {
102
+ const result = await channel.checkQueue(channelName);
103
+ const messageCount = result.messageCount;
104
+ console.log(`MQ队列中有 ${messageCount} 条消息`);
105
+ const length = queryHook ? !!queryHook() : 0;
106
+ console.log(`REDIS队列中有 ${messageCount} 条消息`);
107
+ if (messageCount <= 0 && length === 0) {
108
+ console.log(`即将重启此服务~`);
109
+ shelljs.exec(`pm2 reload ${pmId}`);
110
+ }
111
+ } catch (e) {
112
+ console.log(`重启失败~`);
113
+ }
114
+ }, autoReload)
115
+ }
96
116
  finish && finish();
97
117
  })
98
118
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amqplib-init",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "消息队列初始化",
5
5
  "main": "index.js",
6
6
  "scripts": {