summaryrefslogtreecommitdiff
path: root/src/daemons/queue-stats.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-03-10 19:16:33 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-03-10 19:16:33 +0900
commit80a2172715b6dd225a331d8f2cbccc78dcbd1302 (patch)
tree83915294feef374ae5a9baaa6754a50d549b386f /src/daemons/queue-stats.ts
parentImprove redis config (diff)
downloadsharkey-80a2172715b6dd225a331d8f2cbccc78dcbd1302.tar.gz
sharkey-80a2172715b6dd225a331d8f2cbccc78dcbd1302.tar.bz2
sharkey-80a2172715b6dd225a331d8f2cbccc78dcbd1302.zip
Resolve #4462
Diffstat (limited to 'src/daemons/queue-stats.ts')
-rw-r--r--src/daemons/queue-stats.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/daemons/queue-stats.ts b/src/daemons/queue-stats.ts
new file mode 100644
index 0000000000..26f2bf7c03
--- /dev/null
+++ b/src/daemons/queue-stats.ts
@@ -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);
+}