From 92348fb526a103bf9d9d6d9d652b9301a6b3a6e0 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 13 May 2024 12:53:44 +0100 Subject: [PATCH 1/2] Changing the logic of how automation thread timeout gets applied, so that it can be used properly. --- .../builder/src/stores/builder/automations.js | 15 +++++++++++---- packages/server/src/api/controllers/automation.ts | 3 +-- packages/server/src/environment.ts | 10 ++++++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/builder/src/stores/builder/automations.js b/packages/builder/src/stores/builder/automations.js index a31b05a8d8..90ba88b3e7 100644 --- a/packages/builder/src/stores/builder/automations.js +++ b/packages/builder/src/stores/builder/automations.js @@ -166,10 +166,17 @@ const automationActions = store => ({ await store.actions.save(newAutomation) }, test: async (automation, testData) => { - const result = await API.testAutomation({ - automationId: automation?._id, - testData, - }) + const baseError = "Something went wrong testing your automation" + let result + try { + result = await API.testAutomation({ + automationId: automation?._id, + testData, + }) + } catch (err) { + const message = err.message || err.status || JSON.stringify(err) + throw `${baseError} - ${message}` + } if (!result?.trigger && !result?.steps?.length) { if (result?.err?.code === "usage_limit_exceeded") { throw "You have exceeded your automation quota" diff --git a/packages/server/src/api/controllers/automation.ts b/packages/server/src/api/controllers/automation.ts index b986b5232b..5b199341b1 100644 --- a/packages/server/src/api/controllers/automation.ts +++ b/packages/server/src/api/controllers/automation.ts @@ -279,8 +279,7 @@ export async function trigger(ctx: UserCtx) { { fields: ctx.request.body.fields, timeout: - ctx.request.body.timeout * 1000 || - env.getDefaults().AUTOMATION_SYNC_TIMEOUT, + ctx.request.body.timeout * 1000 || env.AUTOMATION_THREAD_TIMEOUT, }, { getResponses: true } ) diff --git a/packages/server/src/environment.ts b/packages/server/src/environment.ts index d9d299d5fa..2c91f1cb48 100644 --- a/packages/server/src/environment.ts +++ b/packages/server/src/environment.ts @@ -20,7 +20,7 @@ function parseIntSafe(number?: string) { const DEFAULTS = { QUERY_THREAD_TIMEOUT: 15000, - AUTOMATION_THREAD_TIMEOUT: 12000, + AUTOMATION_THREAD_TIMEOUT: 15000, AUTOMATION_SYNC_TIMEOUT: 120000, AUTOMATION_MAX_ITERATIONS: 200, JS_PER_EXECUTION_TIME_LIMIT_MS: 1500, @@ -34,6 +34,10 @@ const DEFAULTS = { const QUERY_THREAD_TIMEOUT = parseIntSafe(process.env.QUERY_THREAD_TIMEOUT) || DEFAULTS.QUERY_THREAD_TIMEOUT +const DEFAULT_AUTOMATION_TIMEOUT = + QUERY_THREAD_TIMEOUT > DEFAULTS.AUTOMATION_THREAD_TIMEOUT + ? QUERY_THREAD_TIMEOUT + : DEFAULTS.AUTOMATION_THREAD_TIMEOUT const environment = { // features APP_FEATURES: process.env.APP_FEATURES, @@ -75,9 +79,7 @@ const environment = { QUERY_THREAD_TIMEOUT: QUERY_THREAD_TIMEOUT, AUTOMATION_THREAD_TIMEOUT: parseIntSafe(process.env.AUTOMATION_THREAD_TIMEOUT) || - DEFAULTS.AUTOMATION_THREAD_TIMEOUT > QUERY_THREAD_TIMEOUT - ? DEFAULTS.AUTOMATION_THREAD_TIMEOUT - : QUERY_THREAD_TIMEOUT, + DEFAULT_AUTOMATION_TIMEOUT, BB_ADMIN_USER_EMAIL: process.env.BB_ADMIN_USER_EMAIL, BB_ADMIN_USER_PASSWORD: process.env.BB_ADMIN_USER_PASSWORD, PLUGINS_DIR: process.env.PLUGINS_DIR || DEFAULTS.PLUGINS_DIR, From 58cda93b08f94e4698138e9c0d8541a156127f88 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 13 May 2024 13:33:59 +0100 Subject: [PATCH 2/2] PR comments. --- packages/builder/src/stores/builder/automations.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/builder/src/stores/builder/automations.js b/packages/builder/src/stores/builder/automations.js index 90ba88b3e7..cbe48cef33 100644 --- a/packages/builder/src/stores/builder/automations.js +++ b/packages/builder/src/stores/builder/automations.js @@ -166,7 +166,6 @@ const automationActions = store => ({ await store.actions.save(newAutomation) }, test: async (automation, testData) => { - const baseError = "Something went wrong testing your automation" let result try { result = await API.testAutomation({ @@ -175,7 +174,7 @@ const automationActions = store => ({ }) } catch (err) { const message = err.message || err.status || JSON.stringify(err) - throw `${baseError} - ${message}` + throw `Automation test failed - ${message}` } if (!result?.trigger && !result?.steps?.length) { if (result?.err?.code === "usage_limit_exceeded") {