Merge pull request #13015 from Budibase/fix-threaded-js-bindings
Init jsrunners on threads
This commit is contained in:
commit
f8cf6a06b7
|
@ -2,6 +2,7 @@ import { QueryVariable } from "./definitions"
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
import * as db from "../db"
|
import * as db from "../db"
|
||||||
import { redis, db as dbCore } from "@budibase/backend-core"
|
import { redis, db as dbCore } from "@budibase/backend-core"
|
||||||
|
import * as jsRunner from "../jsRunner"
|
||||||
|
|
||||||
const VARIABLE_TTL_SECONDS = 3600
|
const VARIABLE_TTL_SECONDS = 3600
|
||||||
let client: any
|
let client: any
|
||||||
|
@ -29,7 +30,9 @@ export function threadSetup() {
|
||||||
console.debug(`[${env.FORKED_PROCESS_NAME}] thread setup skipped`)
|
console.debug(`[${env.FORKED_PROCESS_NAME}] thread setup skipped`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.debug(`[${env.FORKED_PROCESS_NAME}] thread setup running`)
|
console.debug(`[${env.FORKED_PROCESS_NAME}] thread setup running`)
|
||||||
|
jsRunner.init()
|
||||||
db.init()
|
db.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
const vm = require("vm")
|
||||||
const handlebars = require("handlebars")
|
const handlebars = require("handlebars")
|
||||||
const { registerAll, registerMinimum } = require("./helpers/index")
|
const { registerAll, registerMinimum } = require("./helpers/index")
|
||||||
const processors = require("./processors")
|
const processors = require("./processors")
|
||||||
|
@ -402,3 +403,19 @@ const errors = require("./errors")
|
||||||
module.exports.JsErrorTimeout = errors.JsErrorTimeout
|
module.exports.JsErrorTimeout = errors.JsErrorTimeout
|
||||||
|
|
||||||
module.exports.helpersToRemoveForJs = helpersToRemoveForJs
|
module.exports.helpersToRemoveForJs = helpersToRemoveForJs
|
||||||
|
|
||||||
|
if (process && !process.env.NO_JS) {
|
||||||
|
/**
|
||||||
|
* Use polyfilled vm to run JS scripts in a browser Env
|
||||||
|
*/
|
||||||
|
javascript.setJSRunner((js, context) => {
|
||||||
|
context = {
|
||||||
|
...context,
|
||||||
|
alert: undefined,
|
||||||
|
setInterval: undefined,
|
||||||
|
setTimeout: undefined,
|
||||||
|
}
|
||||||
|
vm.createContext(context)
|
||||||
|
return vm.runInNewContext(js, context, { timeout: 1000 })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import vm from "vm"
|
|
||||||
import templates from "./index.js"
|
import templates from "./index.js"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,20 +23,4 @@ export const setOnErrorLog = templates.setOnErrorLog
|
||||||
export const FIND_ANY_HBS_REGEX = templates.FIND_ANY_HBS_REGEX
|
export const FIND_ANY_HBS_REGEX = templates.FIND_ANY_HBS_REGEX
|
||||||
export const helpersToRemoveForJs = templates.helpersToRemoveForJs
|
export const helpersToRemoveForJs = templates.helpersToRemoveForJs
|
||||||
|
|
||||||
if (process && !process.env.NO_JS) {
|
|
||||||
/**
|
|
||||||
* Use polyfilled vm to run JS scripts in a browser Env
|
|
||||||
*/
|
|
||||||
setJSRunner((js, context) => {
|
|
||||||
context = {
|
|
||||||
...context,
|
|
||||||
alert: undefined,
|
|
||||||
setInterval: undefined,
|
|
||||||
setTimeout: undefined,
|
|
||||||
}
|
|
||||||
vm.createContext(context)
|
|
||||||
return vm.runInNewContext(js, context, { timeout: 1000 })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export * from "./errors.js"
|
export * from "./errors.js"
|
||||||
|
|
Loading…
Reference in New Issue