mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-25 18:03:09 +02:00
f6154dc0af
Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> Co-authored-by: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com>
60 lines
1.2 KiB
TypeScript
60 lines
1.2 KiB
TypeScript
import Xev from 'xev';
|
|
import { deliverQueue, inboxQueue } from '../queue';
|
|
|
|
const ev = new Xev();
|
|
|
|
const interval = 10000;
|
|
|
|
/**
|
|
* Report queue stats regularly
|
|
*/
|
|
export default function() {
|
|
const log = [] as any[];
|
|
|
|
ev.on('requestQueueStatsLog', x => {
|
|
ev.emit(`queueStatsLog:${x.id}`, log.slice(0, x.length || 50));
|
|
});
|
|
|
|
let activeDeliverJobs = 0;
|
|
let activeInboxJobs = 0;
|
|
|
|
deliverQueue.on('global:active', () => {
|
|
activeDeliverJobs++;
|
|
});
|
|
|
|
inboxQueue.on('global:active', () => {
|
|
activeInboxJobs++;
|
|
});
|
|
|
|
async function tick() {
|
|
const deliverJobCounts = await deliverQueue.getJobCounts();
|
|
const inboxJobCounts = await inboxQueue.getJobCounts();
|
|
|
|
const stats = {
|
|
deliver: {
|
|
activeSincePrevTick: activeDeliverJobs,
|
|
active: deliverJobCounts.active,
|
|
waiting: deliverJobCounts.waiting,
|
|
delayed: deliverJobCounts.delayed
|
|
},
|
|
inbox: {
|
|
activeSincePrevTick: activeInboxJobs,
|
|
active: inboxJobCounts.active,
|
|
waiting: inboxJobCounts.waiting,
|
|
delayed: inboxJobCounts.delayed
|
|
},
|
|
};
|
|
|
|
ev.emit('queueStats', stats);
|
|
|
|
log.unshift(stats);
|
|
if (log.length > 200) log.pop();
|
|
|
|
activeDeliverJobs = 0;
|
|
activeInboxJobs = 0;
|
|
}
|
|
|
|
tick();
|
|
|
|
setInterval(tick, interval);
|
|
}
|