diff --git a/packages/backend-core/src/queue/inMemoryQueue.ts b/packages/backend-core/src/queue/inMemoryQueue.ts index dd8d3daa37..5c52c693fb 100644 --- a/packages/backend-core/src/queue/inMemoryQueue.ts +++ b/packages/backend-core/src/queue/inMemoryQueue.ts @@ -30,9 +30,10 @@ function newJob(queue: string, message: any, opts?: JobOptions): JobMessage { } /** - * This is designed to replicate Bull (https://github.com/OptimalBits/bull) in memory as a sort of mock. - * It is relatively simple, using an event emitter internally to register when messages are available - * to the consumers - in can support many inputs and many consumers. + * This is designed to replicate Bull (https://github.com/OptimalBits/bull) in + * memory as a sort of mock. It is relatively simple, using an event emitter + * internally to register when messages are available to the consumers - in can + * support many inputs and many consumers. */ class InMemoryQueue implements Partial { _name: string diff --git a/packages/server/src/automations/bullboard.ts b/packages/server/src/automations/bullboard.ts index aa4287b2d0..349282e863 100644 --- a/packages/server/src/automations/bullboard.ts +++ b/packages/server/src/automations/bullboard.ts @@ -5,9 +5,9 @@ import * as automation from "../threads/automation" import { backups } from "@budibase/pro" import { getAppMigrationQueue } from "../appMigrations/queue" import { createBullBoard } from "@bull-board/api" -import BullQueue from "bull" +import { AutomationData } from "@budibase/types" -export const automationQueue: BullQueue.Queue = queue.createQueue( +export const automationQueue = queue.createQueue( queue.JobQueue.AUTOMATION, { removeStalledCb: automation.removeStalled } ) @@ -16,24 +16,20 @@ const PATH_PREFIX = "/bulladmin" export async function init() { // Set up queues for bull board admin + const queues = [new BullAdapter(automationQueue)] + const backupQueue = backups.getBackupQueue() - const appMigrationQueue = getAppMigrationQueue() - const queues = [automationQueue] if (backupQueue) { - queues.push(backupQueue) + queues.push(new BullAdapter(backupQueue)) } + + const appMigrationQueue = getAppMigrationQueue() if (appMigrationQueue) { - queues.push(appMigrationQueue) + queues.push(new BullAdapter(appMigrationQueue)) } - const adapters = [] - const serverAdapter: any = new KoaAdapter() - for (let queue of queues) { - adapters.push(new BullAdapter(queue)) - } - createBullBoard({ - queues: adapters, - serverAdapter, - }) + + const serverAdapter = new KoaAdapter() + createBullBoard({ queues, serverAdapter }) serverAdapter.setBasePath(PATH_PREFIX) return serverAdapter.registerPlugin() } diff --git a/packages/server/src/automations/index.ts b/packages/server/src/automations/index.ts index 4ef3210932..5f9ca1aa60 100644 --- a/packages/server/src/automations/index.ts +++ b/packages/server/src/automations/index.ts @@ -1,7 +1,6 @@ import { processEvent } from "./utils" import { automationQueue } from "./bullboard" import { rebootTrigger } from "./triggers" -import BullQueue from "bull" import { automationsEnabled } from "../features" export { automationQueue } from "./bullboard" @@ -25,6 +24,6 @@ export async function init() { return promise } -export function getQueues(): BullQueue.Queue[] { - return [automationQueue] +export function getQueue() { + return automationQueue } diff --git a/packages/server/src/automations/tests/triggers/cron.spec.ts b/packages/server/src/automations/tests/triggers/cron.spec.ts new file mode 100644 index 0000000000..af82eb3797 --- /dev/null +++ b/packages/server/src/automations/tests/triggers/cron.spec.ts @@ -0,0 +1,31 @@ +import { createAutomationBuilder } from "../utilities/AutomationTestBuilder" +import TestConfiguration from "../../../tests/utilities/TestConfiguration" +import { getQueue } from "../.." + +describe("cron trigger", () => { + const config = new TestConfiguration() + + beforeEach(async () => { + await config.init() + }) + + afterAll(() => { + config.end() + }) + + it("should run the webhook automation - checking for parameters", async () => { + const queue = getQueue() + expect(await queue.count()).toEqual(0) + + await createAutomationBuilder({ config }) + .cron({ cron: "* * * * *" }) + .serverLog({ + text: "Hello, world!", + }) + .save() + + await config.publish() + + expect(await queue.count()).toEqual(1) + }) +}) diff --git a/packages/server/src/automations/utils.ts b/packages/server/src/automations/utils.ts index 9bfcc6cf8a..83665fc975 100644 --- a/packages/server/src/automations/utils.ts +++ b/packages/server/src/automations/utils.ts @@ -230,7 +230,7 @@ export async function enableCronTrigger(appId: any, automation: Automation) { // can't use getAppDB here as this is likely to be called from dev app, // but this call could be for dev app or prod app, need to just use what // was passed in - await dbCore.doWithDB(appId, async (db: any) => { + await dbCore.doWithDB(appId, async db => { const response = await db.put(automation) automation._id = response.id automation._rev = response.rev