-
Notifications
You must be signed in to change notification settings - Fork 37
/
queue.js
41 lines (32 loc) · 898 Bytes
/
queue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
const pino = require('pino');
const log = logger.child({ module: 'stats/queue' });
/**
* Continuously monitor the queue, printing information such as the number of enqueued messages.
*
* @param {Queue} queue - The queue instance.
*/
function statQueue(queue) {
// Do nothing if loglevel is higher than info
if (log.levelVal > pino.levels.values.info) {
return;
}
let pending = false;
setInterval(() => {
if (pending) {
log.info('Queue stat is still being retrieved..');
return;
}
pending = true;
queue.stat()
.finally(() => { pending = false; })
.then((stat) => {
log.info({ stat }, 'Queue stat');
}, (err) => {
log.error({ err }, 'Queue stat failed');
})
.done();
}, 15000)
.unref();
}
module.exports = statQueue;