From 3162ba1c300851dcdfc5ac48ec5ddaf50716364f Mon Sep 17 00:00:00 2001 From: colthreepv Date: Fri, 4 Jun 2021 04:00:50 +0200 Subject: [PATCH 1/2] added queues update procedure --- src/index.js | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/src/index.js b/src/index.js index c36b4a6..af9049e 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ const {createBullBoard} = require('@bull-board/api'); const {BullAdapter} = require('@bull-board/api/bullAdapter'); const {BullMQAdapter} = require('@bull-board/api//bullMQAdapter'); const {ExpressAdapter} = require('@bull-board/express'); +const { isDeepStrictEqual } = require('util') const Queue = require('bull'); const bullmq = require('bullmq'); const express = require('express'); @@ -26,25 +27,45 @@ const redisConfig = { const serverAdapter = new ExpressAdapter(); const client = redis.createClient(redisConfig.redis); -const {setQueues} = createBullBoard({queues: [], serverAdapter}); +const { setQueues, replaceQueues } = createBullBoard({queues: [], serverAdapter}); const router = serverAdapter.getRouter(); -client.KEYS(`${config.BULL_PREFIX}:*`, (err, keys) => { - const uniqKeys = new Set(keys.map(key => key.replace(/^.+?:(.+?):.+?$/, '$1'))); - const queueList = Array.from(uniqKeys).sort().map( - (item) => { - if (config.BULL_VERSION === 'BULLMQ') { - return new BullMQAdapter(new bullmq.Queue(item, {connection: redisConfig.redis})); - } +let lastValidQueues = null - return new BullAdapter(new Queue(item, redisConfig)); +const createAdapters = (queues) => queues.map( + (item) => { + if (config.BULL_VERSION === 'BULLMQ') { + return new BullMQAdapter(new bullmq.Queue(item, {connection: redisConfig.redis})); } - ); + + return new BullAdapter(new Queue(item, redisConfig)); + } +); + +client.KEYS(`${config.BULL_PREFIX}:*`, (err, keys) => { + const uniqKeys = new Set(keys.map(key => key.replace(/^.+?:(.+?):.+?$/, '$1'))); + const actualQueues = Array.from(uniqKeys).sort(); + lastValidQueues = actualQueues; + const queueList = createAdapters(actualQueues); setQueues(queueList); - console.log('done!') + console.log('done!'); }); +const updateQueues = () => { + client.KEYS(`${config.BULL_PREFIX}:*`, (err, keys) => { + const uniqKeys = new Set(keys.map(key => key.replace(/^.+?:(.+?):.+?$/, '$1'))); + const actualQueues = Array.from(uniqKeys).sort(); + if (isDeepStrictEqual(lastValidQueues, actualQueues)) return; + + lastValidQueues = actualQueues; + const queueList = createAdapters(actualQueues); + + replaceQueues(queueList); + console.log('detected queue change, updating UI'); + }); +} + const app = express(); app.set('views', __dirname + '/views'); @@ -87,7 +108,15 @@ if (config.AUTH_ENABLED) { app.use(config.HOME_PAGE, router); } +let updateQueuesInterval = null +const gracefullyShutdown = () => clearInterval(updateQueuesInterval) + app.listen(config.PORT, () => { console.log(`bull-board is started http://localhost:${config.PORT}${config.HOME_PAGE}`); console.log(`bull-board is fetching queue list, please wait...`); + + // poor man queue update process + updateQueuesInterval = setInterval(updateQueues, 60 * 1000) + process.on('SIGINT', gracefullyShutdown) + process.on('SIGTERM', gracefullyShutdown) }); From abde56885897e8c5e457317cf5230d8d0403c52e Mon Sep 17 00:00:00 2001 From: colthreepv Date: Fri, 4 Jun 2021 04:01:05 +0200 Subject: [PATCH 2/2] editorconfig says "CRLF" but files are actually LF terminated --- .editorconfig | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.editorconfig b/.editorconfig index fe3d888..acf5112 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,12 +1,12 @@ -root = true - -[*] -end_of_line = crlf -insert_final_newline = true -charset = utf-8 -indent_style = tab -indent_size = 4 - -[{package.json,**.yml}] -indent_style = space -indent_size = 2 +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_style = tab +indent_size = 4 + +[{package.json,**.yml}] +indent_style = space +indent_size = 2