Refactor to use param for doInAutomationContext

This commit is contained in:
Rory Powell 2023-05-17 14:57:29 +01:00
parent 6c412c7cd9
commit f41b134d31
2 changed files with 10 additions and 8 deletions

View File

@ -104,19 +104,19 @@ async function newContext(updates: ContextMap, task: any) {
return Context.run(context, task) return Context.run(context, task)
} }
export async function doInAutomationContext( export async function doInAutomationContext(params: {
appId: string, appId: string,
automationId: string, automationId: string,
task: any task: any
): Promise<any> { }): Promise<any> {
const tenantId = getTenantIDFromAppID(appId) const tenantId = getTenantIDFromAppID(params.appId)
return newContext( return newContext(
{ {
tenantId, tenantId,
appId, appId: params.appId,
automationId, automationId: params.automationId,
}, },
task params.task
) )
} }

View File

@ -26,7 +26,7 @@ function loggingArgs(job: AutomationJob) {
export async function processEvent(job: AutomationJob) { export async function processEvent(job: AutomationJob) {
const appId = job.data.event.appId! const appId = job.data.event.appId!
const automationId = job.data.automation._id! const automationId = job.data.automation._id!
return await context.doInAutomationContext(appId, automationId, async () => { const task = async () => {
try { try {
// need to actually await these so that an error can be captured properly // need to actually await these so that an error can be captured properly
console.log("automation running", loggingArgs(job)) 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)) console.error(`automation was unable to run`, err, loggingArgs(job))
return { err } return { err }
} }
}) }
return await context.doInAutomationContext({ appId, automationId, task })
} }
export async function updateTestHistory( export async function updateTestHistory(