2020-09-10 16:00:21 +02:00
|
|
|
const triggers = require("./triggers")
|
2020-09-14 15:32:20 +02:00
|
|
|
const environment = require("../environment")
|
2020-09-11 19:47:22 +02:00
|
|
|
const workerFarm = require("worker-farm")
|
|
|
|
const singleThread = require("./thread")
|
2020-09-10 16:00:21 +02:00
|
|
|
|
2020-09-11 19:47:22 +02:00
|
|
|
let workers = workerFarm(require.resolve("./thread"))
|
2020-09-10 16:00:21 +02:00
|
|
|
|
2020-09-11 19:47:22 +02:00
|
|
|
function runWorker(job) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
workers(job, err => {
|
|
|
|
if (err) {
|
|
|
|
reject(err)
|
|
|
|
} else {
|
|
|
|
resolve()
|
2020-09-10 16:00:21 +02:00
|
|
|
}
|
2020-09-11 19:47:22 +02:00
|
|
|
})
|
|
|
|
})
|
2020-09-10 16:00:21 +02:00
|
|
|
}
|
|
|
|
|
2020-09-11 19:47:22 +02:00
|
|
|
/**
|
|
|
|
* This module is built purely to kick off the worker farm and manage the inputs/outputs
|
|
|
|
*/
|
2020-09-10 16:00:21 +02:00
|
|
|
module.exports.init = function() {
|
|
|
|
triggers.workflowQueue.process(async job => {
|
2020-09-14 15:32:20 +02:00
|
|
|
if (environment.BUDIBASE_ENVIRONMENT === "PRODUCTION") {
|
2020-09-11 19:47:22 +02:00
|
|
|
await runWorker(job)
|
|
|
|
} else {
|
|
|
|
await singleThread(job)
|
|
|
|
}
|
2020-09-10 16:00:21 +02:00
|
|
|
})
|
|
|
|
}
|