From 7d1dec28da65084557d70b2e6b3a45ce20969e44 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 14 Sep 2021 16:43:06 +0100 Subject: [PATCH] Removing the concept of worker-farm and fixing issues raised in review. --- packages/server/package.json | 1 - packages/server/src/automations/thread.js | 15 +------- .../src/automations/triggerInfo/cron.js | 2 +- .../src/automations/triggerInfo/index.js | 2 +- packages/server/src/automations/utils.js | 37 +------------------ 5 files changed, 6 insertions(+), 51 deletions(-) diff --git a/packages/server/package.json b/packages/server/package.json index f242601d94..97fa7238e7 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -109,7 +109,6 @@ "to-json-schema": "0.2.5", "uuid": "3.3.2", "validate.js": "0.13.1", - "worker-farm": "1.7.0", "yargs": "13.2.4", "zlib": "1.0.5" }, diff --git a/packages/server/src/automations/thread.js b/packages/server/src/automations/thread.js index c810a5a71d..a3e81a2274 100644 --- a/packages/server/src/automations/thread.js +++ b/packages/server/src/automations/thread.js @@ -99,21 +99,10 @@ class Orchestrator { } } -// callback is required for worker-farm to state that the worker thread has completed -module.exports = (job, cb) => { - if (!cb) { - throw "Callback must be defined." - } +module.exports = async job => { const automationOrchestrator = new Orchestrator( job.data.automation, job.data.event ) - automationOrchestrator - .execute() - .then(output => { - cb(null, output) - }) - .catch(err => { - cb(err) - }) + return automationOrchestrator.execute() } diff --git a/packages/server/src/automations/triggerInfo/cron.js b/packages/server/src/automations/triggerInfo/cron.js index 9ef4649b95..31e79a4abf 100644 --- a/packages/server/src/automations/triggerInfo/cron.js +++ b/packages/server/src/automations/triggerInfo/cron.js @@ -1,4 +1,4 @@ -exports.defintion = { +exports.definition = { name: "Cron Trigger", event: "cron:trigger", icon: "ri-timer-line", diff --git a/packages/server/src/automations/triggerInfo/index.js b/packages/server/src/automations/triggerInfo/index.js index 476d37d54c..066993d324 100644 --- a/packages/server/src/automations/triggerInfo/index.js +++ b/packages/server/src/automations/triggerInfo/index.js @@ -11,5 +11,5 @@ exports.definitions = { ROW_DELETED: rowDeleted.definition, WEBHOOK: webhook.definition, APP: app.definition, - CRON: cron.defintion, + CRON: cron.definition, } diff --git a/packages/server/src/automations/utils.js b/packages/server/src/automations/utils.js index 29a8e38b18..f9de64de59 100644 --- a/packages/server/src/automations/utils.js +++ b/packages/server/src/automations/utils.js @@ -1,7 +1,6 @@ const env = require("../environment") -const workerFarm = require("worker-farm") const { getAPIKey, update, Properties } = require("../utilities/usageQuota") -const singleThread = require("./thread") +const runner = require("./thread") const { definitions } = require("./triggerInfo") const webhooks = require("../api/controllers/webhook") const CouchDB = require("../db") @@ -13,32 +12,6 @@ const { MetadataTypes } = require("../constants") const WH_STEP_ID = definitions.WEBHOOK.stepId const CRON_STEP_ID = definitions.CRON.stepId -let workers = workerFarm(require.resolve("./thread")) - -function runWorker(job) { - return new Promise((resolve, reject) => { - workers(job, (err, output) => { - if (err) { - reject(err) - } else { - resolve(output) - } - }) - }) -} - -function runSingleThread(job) { - return new Promise((resolve, reject) => { - singleThread(job, (err, output) => { - if (err) { - reject(err) - } else { - resolve(output) - } - }) - }) -} - async function updateQuota(automation) { const appId = automation.appId const apiObj = await getAPIKey(appId) @@ -53,13 +26,7 @@ exports.processEvent = async job => { job.data.automation.apiKey = await updateQuota(job.data.automation) } // need to actually await these so that an error can be captured properly - let response - if (!env.isProd()) { - response = await runSingleThread(job) - } else { - response = await runWorker(job) - } - return response + return await runner(job) } catch (err) { console.error( `${job.data.automation.appId} automation ${job.data.automation._id} was unable to run - ${err}`