From ea5d04e1d3dbaf22337402c7b736684ff44ad5e7 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 14 Feb 2024 17:15:42 +0000 Subject: [PATCH] Addressing PR comments. --- packages/server/src/api/controllers/automation.ts | 7 +++++-- .../server/src/automations/steps/triggerAutomationRun.ts | 5 +++-- .../src/automations/tests/triggerAutomationRun.spec.ts | 6 +++--- packages/server/src/constants/automations.ts | 6 ------ packages/server/src/constants/index.ts | 2 -- packages/server/src/environment.ts | 1 + 6 files changed, 12 insertions(+), 15 deletions(-) delete mode 100644 packages/server/src/constants/automations.ts diff --git a/packages/server/src/api/controllers/automation.ts b/packages/server/src/api/controllers/automation.ts index 212ef5668f..186b68f3b7 100644 --- a/packages/server/src/api/controllers/automation.ts +++ b/packages/server/src/api/controllers/automation.ts @@ -10,7 +10,7 @@ import { removeDeprecated, } from "../../automations/utils" import { deleteEntityMetadata } from "../../utilities" -import { MetadataTypes, AUTOMATION_SYNC_TIMEOUT } from "../../constants" +import { MetadataTypes } from "../../constants" import { setTestFlag, clearTestFlag } from "../../utilities/redis" import { context, cache, events, db as dbCore } from "@budibase/backend-core" import { automations, features } from "@budibase/pro" @@ -24,6 +24,7 @@ import { import { getActionDefinitions as actionDefs } from "../../automations/actions" import sdk from "../../sdk" import { builderSocket } from "../../websockets" +import env from "../../environment" async function getActionDefinitions() { return removeDeprecated(await actionDefs()) @@ -274,7 +275,9 @@ export async function trigger(ctx: UserCtx) { automation, { fields: ctx.request.body.fields, - timeout: ctx.request.body.timeout * 1000 || AUTOMATION_SYNC_TIMEOUT, + timeout: + ctx.request.body.timeout * 1000 || + env.getDefaults().AUTOMATION_SYNC_TIMEOUT, }, { getResponses: true } ) diff --git a/packages/server/src/automations/steps/triggerAutomationRun.ts b/packages/server/src/automations/steps/triggerAutomationRun.ts index 73c9b3adf1..83e1722877 100644 --- a/packages/server/src/automations/steps/triggerAutomationRun.ts +++ b/packages/server/src/automations/steps/triggerAutomationRun.ts @@ -11,7 +11,7 @@ import { import * as triggers from "../triggers" import { context } from "@budibase/backend-core" import { features } from "@budibase/pro" -import { AUTOMATION_SYNC_TIMEOUT } from "../../constants" +import env from "../../environment" export const definition: AutomationStepSchema = { name: "Trigger an automation", @@ -77,7 +77,8 @@ export async function run({ inputs }: AutomationStepInput) { automation, { fields: { ...fieldParams }, - timeout: inputs.timeout * 1000 || AUTOMATION_SYNC_TIMEOUT, + timeout: + inputs.timeout * 1000 || env.getDefaults().AUTOMATION_SYNC_TIMEOUT, }, { getResponses: true } ) diff --git a/packages/server/src/automations/tests/triggerAutomationRun.spec.ts b/packages/server/src/automations/tests/triggerAutomationRun.spec.ts index 83e3c20bbb..9d699e15fa 100644 --- a/packages/server/src/automations/tests/triggerAutomationRun.spec.ts +++ b/packages/server/src/automations/tests/triggerAutomationRun.spec.ts @@ -3,7 +3,7 @@ jest.spyOn(global.console, "error") import * as setup from "./utilities" import * as automation from "../index" import { serverLogAutomation } from "../../tests/utilities/structures" -import { AUTOMATION_ASYNC_TIMEOUT } from "../../constants" +import env from "../../environment" describe("Test triggering an automation from another automation", () => { let config = setup.getConfig() @@ -25,7 +25,7 @@ describe("Test triggering an automation from another automation", () => { const inputs: any = { automation: { automationId: newAutomation._id, - timeout: AUTOMATION_ASYNC_TIMEOUT, + timeout: env.getDefaults().AUTOMATION_THREAD_TIMEOUT, }, } const res = await setup.runStep( @@ -40,7 +40,7 @@ describe("Test triggering an automation from another automation", () => { const inputs: any = { automation: { automationId: null, - timeout: AUTOMATION_ASYNC_TIMEOUT, + timeout: env.getDefaults().AUTOMATION_THREAD_TIMEOUT, }, } const res = await setup.runStep( diff --git a/packages/server/src/constants/automations.ts b/packages/server/src/constants/automations.ts deleted file mode 100644 index 6688cbedb7..0000000000 --- a/packages/server/src/constants/automations.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Duration } from "@budibase/backend-core" -import env from "../environment" - -const defaults = env.getDefaults() -export const AUTOMATION_SYNC_TIMEOUT = Duration.fromMinutes(2).toMs() -export const AUTOMATION_ASYNC_TIMEOUT = defaults.QUERY_THREAD_TIMEOUT diff --git a/packages/server/src/constants/index.ts b/packages/server/src/constants/index.ts index 530cc536ca..49f1d01afb 100644 --- a/packages/server/src/constants/index.ts +++ b/packages/server/src/constants/index.ts @@ -6,8 +6,6 @@ import { TableSourceType, } from "@budibase/types" -export * from "./automations" - export enum FilterTypes { STRING = "string", FUZZY = "fuzzy", diff --git a/packages/server/src/environment.ts b/packages/server/src/environment.ts index ec70ced66c..20142776b8 100644 --- a/packages/server/src/environment.ts +++ b/packages/server/src/environment.ts @@ -21,6 +21,7 @@ function parseIntSafe(number?: string) { const DEFAULTS = { QUERY_THREAD_TIMEOUT: 10000, AUTOMATION_THREAD_TIMEOUT: 12000, + AUTOMATION_SYNC_TIMEOUT: 120000, AUTOMATION_MAX_ITERATIONS: 200, JS_PER_EXECUTION_TIME_LIMIT_MS: 1000, TEMPLATE_REPOSITORY: "app",