amqplib-init 1.1.4 → 1.1.5
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.
- package/index.js +20 -1
- 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,23 @@ module.exports = {
|
|
|
93
95
|
amqpInit(true);
|
|
94
96
|
});
|
|
95
97
|
chalk.log(`✳️-队列已启动: finish~`);
|
|
98
|
+
if (autoReload > 0) {
|
|
99
|
+
setInterval(async _=> {
|
|
100
|
+
try {
|
|
101
|
+
const result = await channel.checkQueue(channelName);
|
|
102
|
+
const messageCount = result.messageCount;
|
|
103
|
+
console.log(`MQ队列中有 ${messageCount} 条消息`);
|
|
104
|
+
const length = queryHook ? !!queryHook() : 0;
|
|
105
|
+
console.log(`REDIS队列中有 ${messageCount} 条消息`);
|
|
106
|
+
if (messageCount <= 0 && length === 0) {
|
|
107
|
+
console.log(`即将重启此服务~`);
|
|
108
|
+
shelljs.exec(`pm2 reload ${pmId}`);
|
|
109
|
+
}
|
|
110
|
+
} catch (e) {
|
|
111
|
+
console.log(`重启失败~`);
|
|
112
|
+
}
|
|
113
|
+
}, autoReload)
|
|
114
|
+
}
|
|
96
115
|
finish && finish();
|
|
97
116
|
})
|
|
98
117
|
}
|