budibase/packages/server/src/threads/utils.js

34 lines
829 B
JavaScript
Raw Normal View History

const env = require("../environment")
const CouchDB = require("../db")
const { init } = require("@budibase/auth")
2021-12-16 17:58:15 +01:00
const redis = require("@budibase/auth/redis")
const { SEPARATOR } = require("@budibase/auth/db")
let client
if (!client) {
client = await new redis.Client(redis.utils.Databases.QUERY_VARS).init()
}
process.on("exit", async () => {
if (client) await client.finish()
})
exports.threadSetup = () => {
2021-12-15 13:26:29 +01:00
// don't run this if not threading
if (env.isTest() || env.DISABLE_THREADING) {
return
}
// when thread starts, make sure it is recorded
env.setInThread()
init(CouchDB)
}
2021-12-16 17:58:15 +01:00
function makeVariableKey(queryId, variable) {
return `${queryId}${SEPARATOR}${variable}`
}
exports.checkCacheForDynamicVariable = async (queryId, variable) => {
await client.get(makeVariableKey(queryId, variable))
}