2020-09-10 16:00:21 +02:00
|
|
|
const triggers = require("./triggers")
|
2020-09-18 17:50:52 +02:00
|
|
|
const actions = require("./actions")
|
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() {
|
2020-09-18 17:50:52 +02:00
|
|
|
actions.init().then(() => {
|
|
|
|
triggers.workflowQueue.process(async job => {
|
|
|
|
if (environment.BUDIBASE_ENVIRONMENT === "PRODUCTION") {
|
|
|
|
await runWorker(job)
|
|
|
|
} else {
|
|
|
|
await singleThread(job)
|
|
|
|
}
|
|
|
|
})
|
2020-09-10 16:00:21 +02:00
|
|
|
})
|
|
|
|
}
|