diff --git a/packages/backend-core/src/context/mainContext.ts b/packages/backend-core/src/context/mainContext.ts index 492e0abb10..41e6579384 100644 --- a/packages/backend-core/src/context/mainContext.ts +++ b/packages/backend-core/src/context/mainContext.ts @@ -104,19 +104,19 @@ async function newContext(updates: ContextMap, task: any) { return Context.run(context, task) } -export async function doInAutomationContext( +export async function doInAutomationContext(params: { appId: string, automationId: string, task: any -): Promise { - const tenantId = getTenantIDFromAppID(appId) +}): Promise { + const tenantId = getTenantIDFromAppID(params.appId) return newContext( { tenantId, - appId, - automationId, + appId: params.appId, + automationId: params.automationId, }, - task + params.task ) } diff --git a/packages/server/src/automations/utils.ts b/packages/server/src/automations/utils.ts index 50a3af2cbb..d9f19013ee 100644 --- a/packages/server/src/automations/utils.ts +++ b/packages/server/src/automations/utils.ts @@ -26,7 +26,7 @@ function loggingArgs(job: AutomationJob) { export async function processEvent(job: AutomationJob) { const appId = job.data.event.appId! const automationId = job.data.automation._id! - return await context.doInAutomationContext(appId, automationId, async () => { + const task = async () => { try { // need to actually await these so that an error can be captured properly console.log("automation running", loggingArgs(job)) @@ -41,7 +41,9 @@ export async function processEvent(job: AutomationJob) { console.error(`automation was unable to run`, err, loggingArgs(job)) return { err } } - }) + } + + return await context.doInAutomationContext({ appId, automationId, task }) } export async function updateTestHistory(