Some typing improvements in automation queues.
This commit is contained in:
parent
4743cc0888
commit
bd6d6534be
|
@ -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<Queue> {
|
||||
_name: string
|
||||
|
|
|
@ -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<AutomationData>(
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue