Fixing some un-identified listeners, queue messages not being correctly printed, also improving the mechanism for detecting if in the main thread or not.

This commit is contained in:
mike12345567 2023-05-04 17:05:36 +01:00
parent 303a029184
commit 0d7959f720
4 changed files with 14 additions and 10 deletions

View File

@ -40,6 +40,12 @@ function logging(queue: Queue, jobQueue: JobQueue) {
case JobQueue.APP_BACKUP:
eventType = "app-backup-event"
break
case JobQueue.AUDIT_LOG:
eventType = "audit-log-event"
break
case JobQueue.SYSTEM_EVENT_QUEUE:
eventType = "system-event"
break
}
if (process.env.NODE_DEBUG?.includes("bull")) {
queue

View File

@ -34,8 +34,6 @@ function parseIntSafe(number?: string) {
}
}
let inThread = false
const environment = {
// important - prefer app port to generic port
PORT: process.env.APP_PORT || process.env.PORT,
@ -95,12 +93,8 @@ const environment = {
isProd: () => {
return !isDev()
},
// used to check if already in a thread, don't thread further
setInThread: () => {
inThread = true
},
isInThread: () => {
return inThread
return process.env.FORKED_PROCESS
},
}

View File

@ -39,6 +39,12 @@ export class Thread {
const workerOpts: any = {
autoStart: true,
maxConcurrentWorkers: this.count,
workerOptions: {
env: {
...process.env,
FORKED_PROCESS: "1",
},
},
}
if (opts.timeoutMs) {
this.timeoutMs = opts.timeoutMs

View File

@ -25,11 +25,9 @@ function makeVariableKey(queryId: string, variable: string) {
export function threadSetup() {
// don't run this if not threading
if (env.isTest() || env.DISABLE_THREADING) {
if (env.isTest() || env.DISABLE_THREADING || !env.isInThread()) {
return
}
// when thread starts, make sure it is recorded
env.setInThread()
db.init()
}