1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00
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 {