From 80d4220cb5dccaab5b3b48faa13f26eeb15e6dae Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 26 Oct 2022 18:50:40 +0100 Subject: [PATCH] Adding backup queue to bullboard if enabled. --- packages/server/src/app.ts | 42 +++++++++++--------- packages/server/src/automations/bullboard.js | 7 +++- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/packages/server/src/app.ts b/packages/server/src/app.ts index d8ed2c872b..a5dfcc6e80 100644 --- a/packages/server/src/app.ts +++ b/packages/server/src/app.ts @@ -54,19 +54,6 @@ app.use( }) ) -app.use(pino(pinoSettings())) - -if (!env.isTest()) { - const plugin = bullboard.init() - app.use(plugin) -} - -app.context.eventEmitter = eventEmitter -app.context.auth = {} - -// api routes -app.use(api.router.routes()) - if (env.isProd()) { env._set("NODE_ENV", "production") Sentry.init() @@ -104,7 +91,22 @@ server.on("close", async () => { } }) -const initPro = async () => { +async function initRoutes() { + app.use(pino(pinoSettings())) + + if (!env.isTest()) { + const plugin = await bullboard.init() + app.use(plugin) + } + + app.context.eventEmitter = eventEmitter + app.context.auth = {} + + // api routes + app.use(api.router.routes()) +} + +async function initPro() { await pro.init({ backups: { processing: { @@ -179,11 +181,13 @@ module.exports = server.listen(env.PORT || 0, async () => { // check for version updates await installation.checkInstallVersion() - // done last - these will never complete - let promises = [] - promises.push(automations.init()) - promises.push(initPro()) - await Promise.all(promises) + // get the references to the queue promises, don't await as + // they will never end, unless the processing stops + let queuePromises = [] + queuePromises.push(automations.init()) + queuePromises.push(initPro()) + // bring routes online as final step once everything ready + await initRoutes() }) const shutdown = () => { diff --git a/packages/server/src/automations/bullboard.js b/packages/server/src/automations/bullboard.js index c4f33e07a9..dd4a6aa383 100644 --- a/packages/server/src/automations/bullboard.js +++ b/packages/server/src/automations/bullboard.js @@ -3,6 +3,7 @@ const { BullAdapter } = require("@bull-board/api/bullAdapter") const { KoaAdapter } = require("@bull-board/koa") const { queue } = require("@budibase/backend-core") const automation = require("../threads/automation") +const { backups } = require("@budibase/pro") let automationQueue = queue.createQueue( queue.JobQueue.AUTOMATION, @@ -11,9 +12,13 @@ let automationQueue = queue.createQueue( const PATH_PREFIX = "/bulladmin" -exports.init = () => { +exports.init = async () => { // Set up queues for bull board admin + const backupQueue = await backups.getBackupQueue() const queues = [automationQueue] + if (backupQueue) { + queues.push(backupQueue) + } const adapters = [] const serverAdapter = new KoaAdapter() for (let queue of queues) {