This commit is contained in:
Rory Powell 2023-05-30 19:16:36 +01:00
parent ef9fc94728
commit b0783d373a
3 changed files with 15 additions and 9 deletions

View File

@ -15,7 +15,7 @@ function sanitiseResults(results: AutomationResults) {
}
step.outputs = {
message,
success: step.outputs.success
success: step.outputs.success,
}
}
}
@ -29,7 +29,7 @@ export async function storeLog(
return
}
const bytes = sizeof(results)
if ((bytes / MB_IN_BYTES) > MAX_LOG_SIZE_MB) {
if (bytes / MB_IN_BYTES > MAX_LOG_SIZE_MB) {
sanitiseResults(results)
}
await automations.logs.storeLog(automation, results)

View File

@ -507,7 +507,10 @@ export function execute(job: Job<AutomationData>, callback: WorkerCallback) {
if (!automationId) {
throw new Error("Unable to execute, event doesn't contain automation ID.")
}
return context.doInAutomationContext({ appId, automationId, task: async () => {
return context.doInAutomationContext({
appId,
automationId,
task: async () => {
const envVars = await sdkUtils.getEnvironmentVariables()
// put into automation thread for whole context
await context.doInEnvironmentContext(envVars, async () => {
@ -519,7 +522,8 @@ export function execute(job: Job<AutomationData>, callback: WorkerCallback) {
callback(err)
}
})
}})
},
})
}
export function executeSynchronously(job: Job) {

View File

@ -38,7 +38,9 @@ export class Thread {
this.count = opts.count ? opts.count : 1
this.disableThreading = this.shouldDisableThreading()
if (!this.disableThreading) {
console.debug(`[${env.FORKED_PROCESS_NAME}] initialising worker farm type=${type}`)
console.debug(
`[${env.FORKED_PROCESS_NAME}] initialising worker farm type=${type}`
)
const workerOpts: any = {
autoStart: true,
maxConcurrentWorkers: this.count,
@ -57,7 +59,9 @@ export class Thread {
this.workers = workerFarm(workerOpts, typeToFile(type), ["execute"])
Thread.workerRefs.push(this.workers)
} else {
console.debug(`[${env.FORKED_PROCESS_NAME}] skipping worker farm type=${type}`)
console.debug(
`[${env.FORKED_PROCESS_NAME}] skipping worker farm type=${type}`
)
}
}
@ -76,9 +80,7 @@ export class Thread {
function fire(worker: any) {
worker.execute(job, (err: any, response: any) => {
if (err && err.type === "TimeoutError") {
reject(
new Error(`Thread timeout exceeded ${timeout}ms timeout.`)
)
reject(new Error(`Thread timeout exceeded ${timeout}ms timeout.`))
} else if (err) {
reject(err)
} else {