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)
}
export async function doInAutomationContext(
export async function doInAutomationContext(params: {
appId: string,
automationId: string,
task: any
): Promise<any> {
const tenantId = getTenantIDFromAppID(appId)
}): Promise<any> {
const tenantId = getTenantIDFromAppID(params.appId)
return newContext(
{
tenantId,
appId,
automationId,
appId: params.appId,
automationId: params.automationId,
},
task
params.task
)
}

View File

@ -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(