Resolve #4462
This commit is contained in:
parent
5a0a297634
commit
80a2172715
9 changed files with 249 additions and 0 deletions
43
src/daemons/queue-stats.ts
Normal file
43
src/daemons/queue-stats.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import * as Deque from 'double-ended-queue';
|
||||
import Xev from 'xev';
|
||||
import { deliverQueue, inboxQueue } from '../queue';
|
||||
|
||||
const ev = new Xev();
|
||||
|
||||
const interval = 1000;
|
||||
|
||||
/**
|
||||
* Report queue stats regularly
|
||||
*/
|
||||
export default function() {
|
||||
const log = new Deque<any>();
|
||||
|
||||
ev.on('requestQueueStatsLog', x => {
|
||||
ev.emit(`queueStatsLog:${x.id}`, log.toArray().slice(0, x.length || 50));
|
||||
});
|
||||
|
||||
async function tick() {
|
||||
const deliverJobCounts = await deliverQueue.getJobCounts();
|
||||
const inboxJobCounts = await inboxQueue.getJobCounts();
|
||||
|
||||
const stats = {
|
||||
deliver: {
|
||||
active: Math.floor(Math.random() * 100),
|
||||
delayed: Math.floor(Math.random() * 1000),
|
||||
},
|
||||
inbox: {
|
||||
active: Math.floor(Math.random() * 100),
|
||||
delayed: Math.floor(Math.random() * 1000),
|
||||
}
|
||||
};
|
||||
|
||||
ev.emit('queueStats', stats);
|
||||
|
||||
log.unshift(stats);
|
||||
if (log.length > 200) log.pop();
|
||||
}
|
||||
|
||||
tick();
|
||||
|
||||
setInterval(tick, interval);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue