From d1127f32202441b6f2245cadc1950506cdebe58f Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 15 Dec 2021 11:25:52 +0000 Subject: [PATCH] Fixing an issue with automations throwing a Pouch error due to the auth library database not being setup. --- packages/server/src/threads/automation.js | 3 +-- packages/server/src/threads/query.js | 4 +--- packages/server/src/threads/utils.js | 9 +++++++++ 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 packages/server/src/threads/utils.js diff --git a/packages/server/src/threads/automation.js b/packages/server/src/threads/automation.js index 11ee28dbe8..fc9e2a21fc 100644 --- a/packages/server/src/threads/automation.js +++ b/packages/server/src/threads/automation.js @@ -1,6 +1,5 @@ -// when thread starts, make sure it is recorded +require("./utils").threadSetup() const env = require("../environment") -env.setInThread() const actions = require("../automations/actions") const automationUtils = require("../automations/automationUtils") const AutomationEmitter = require("../events/AutomationEmitter") diff --git a/packages/server/src/threads/query.js b/packages/server/src/threads/query.js index 6b0d021e94..6921a6543d 100644 --- a/packages/server/src/threads/query.js +++ b/packages/server/src/threads/query.js @@ -1,6 +1,4 @@ -// when thread starts, make sure it is recorded -const env = require("../environment") -env.setInThread() +require("./utils").threadSetup() const ScriptRunner = require("../utilities/scriptRunner") const { integrations } = require("../integrations") diff --git a/packages/server/src/threads/utils.js b/packages/server/src/threads/utils.js new file mode 100644 index 0000000000..13e9daf711 --- /dev/null +++ b/packages/server/src/threads/utils.js @@ -0,0 +1,9 @@ +const env = require("../environment") +const CouchDB = require("../db") +const { init } = require("@budibase/auth") + +exports.threadSetup = () => { + // when thread starts, make sure it is recorded + env.setInThread() + init(CouchDB) +}