Respond to Adri's feedback.

This commit is contained in:
Sam Rose 2025-02-18 14:01:32 +00:00
parent 5aeac61cd1
commit 6952ca325a
No known key found for this signature in database
3 changed files with 14 additions and 12 deletions

View File

@ -40,6 +40,7 @@ export interface TestQueueMessage<T = any> extends Partial<Job<T>> {
queue: Queue<T> queue: Queue<T>
data: any data: any
opts?: JobOptions opts?: JobOptions
manualTrigger?: boolean
} }
/** /**
@ -90,10 +91,9 @@ export class InMemoryQueue<T = any> implements Partial<Queue<T>> {
this._emitter.on("message", async msg => { this._emitter.on("message", async msg => {
const message = cloneDeep(msg) const message = cloneDeep(msg)
const isManualTrigger = (message as any).manualTrigger === true
// For the purpose of testing, don't trigger cron jobs immediately. // For the purpose of testing, don't trigger cron jobs immediately.
// Require the test to trigger them manually with timestamps. // Require the test to trigger them manually with timestamps.
if (!isManualTrigger && message.opts?.repeat != null) { if (!message.manualTrigger && message.opts?.repeat != null) {
return return
} }
@ -216,8 +216,7 @@ export class InMemoryQueue<T = any> implements Partial<Queue<T>> {
manualTrigger(id: JobId) { manualTrigger(id: JobId) {
for (const message of this._messages) { for (const message of this._messages) {
if (message.id === id) { if (message.id === id) {
const forceMessage = { ...message, manualTrigger: true } this._emitter.emit("message", { ...message, manualTrigger: true })
this._emitter.emit("message", forceMessage)
return return
} }
} }

View File

@ -9,7 +9,7 @@ import {
import { automations } from "@budibase/pro" import { automations } from "@budibase/pro"
import { AutomationData, AutomationStatus } from "@budibase/types" import { AutomationData, AutomationStatus } from "@budibase/types"
import { MAX_AUTOMATION_RECURRING_ERRORS } from "../../../constants" import { MAX_AUTOMATION_RECURRING_ERRORS } from "../../../constants"
import { Job } from "bull" import { queue } from "@budibase/backend-core"
describe("cron trigger", () => { describe("cron trigger", () => {
const config = new TestConfiguration() const config = new TestConfiguration()
@ -80,7 +80,7 @@ describe("cron trigger", () => {
) )
await config.withProdApp(async () => { await config.withProdApp(async () => {
let results: Job<AutomationData>[] = [] let results: queue.TestQueueMessage<AutomationData>[] = []
const removed = await captureAutomationRemovals(automation, async () => { const removed = await captureAutomationRemovals(automation, async () => {
results = await captureAutomationResults(automation, async () => { results = await captureAutomationResults(automation, async () => {
for (let i = 0; i < MAX_AUTOMATION_RECURRING_ERRORS; i++) { for (let i = 0; i < MAX_AUTOMATION_RECURRING_ERRORS; i++) {

View File

@ -120,19 +120,22 @@ export async function captureAutomationMessages(
*/ */
export async function captureAllAutomationResults( export async function captureAllAutomationResults(
f: () => Promise<unknown> f: () => Promise<unknown>
): Promise<Job<AutomationData>[]> { ): Promise<queue.TestQueueMessage<AutomationData>[]> {
const runs: Job<AutomationData>[] = [] const runs: queue.TestQueueMessage<AutomationData>[] = []
const queue = getQueue() const queue = getQueue()
let messagesOutstanding = 0 let messagesOutstanding = 0
const completedListener = async (job: Job<AutomationData>) => { const completedListener = async (
job: queue.TestQueueMessage<AutomationData>
) => {
runs.push(job) runs.push(job)
messagesOutstanding-- messagesOutstanding--
} }
const messageListener = async (message: Job<AutomationData>) => { const messageListener = async (
message: queue.TestQueueMessage<AutomationData>
) => {
// Don't count cron messages, as they don't get triggered automatically. // Don't count cron messages, as they don't get triggered automatically.
const isManualTrigger = (message as any).manualTrigger === true if (!message.manualTrigger && message.opts?.repeat != null) {
if (!isManualTrigger && message.opts?.repeat != null) {
return return
} }
messagesOutstanding++ messagesOutstanding++