From 3859a4159fe9ad89d9ea22319ab47ee7ae38241b Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 10 Feb 2023 14:14:43 +0000 Subject: [PATCH] Minor fix for automations, the wrong function had the environment variables being added to environment, this is very minor, it simply makes sure that environment variables are in context for the whole of the automation runner - e.g. if utilising many datasources each of them doesn't need to re-retrieve the environment variables, instead they will be available based on the env vars retrieved at the start of the execution. --- packages/server/src/threads/automation.ts | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index 91105a2194..74c202c33d 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -464,13 +464,17 @@ export function execute(job: Job, callback: WorkerCallback) { throw new Error("Unable to execute, event doesn't contain app ID.") } return context.doInAppContext(appId, async () => { - const automationOrchestrator = new Orchestrator(job) - try { - const response = await automationOrchestrator.execute() - callback(null, response) - } catch (err) { - callback(err) - } + const envVars = await sdkUtils.getEnvironmentVariables() + // put into automation thread for whole context + await context.doInEnvironmentContext(envVars, async () => { + const automationOrchestrator = new Orchestrator(job) + try { + const response = await automationOrchestrator.execute() + callback(null, response) + } catch (err) { + callback(err) + } + }) }) } @@ -480,11 +484,7 @@ export const removeStalled = async (job: Job) => { throw new Error("Unable to execute, event doesn't contain app ID.") } await context.doInAppContext(appId, async () => { - const envVars = await sdkUtils.getEnvironmentVariables() - // put into automation thread for whole context - await context.doInEnvironmentContext(envVars, async () => { - const automationOrchestrator = new Orchestrator(job) - await automationOrchestrator.stopCron("stalled") - }) + const automationOrchestrator = new Orchestrator(job) + await automationOrchestrator.stopCron("stalled") }) }