fix(netflow): запускать TypeScript worker с собственным загрузчиком
This commit is contained in:
1 parent
7a38bb36aa
commit
19ad294ded
20 files changed
+472
-13
No files matched your search
@@ -58,10 +58,10 @@ let state: FlowListenerState = { bound: false, address: null }
|
||||
let wantListen = false
|
||||
let databaseStop: Promise<void> | null = null
|
||||
|
||||
function workerFileUrl(): URL {
|
||||
const ts = import.meta.url.includes(".ts")
|
||||
export function trafficFlowWorkerFileUrl(): URL {
|
||||
const ts = new URL(import.meta.url).pathname.endsWith(".ts")
|
||||
return new URL(
|
||||
ts ? "./traffic-flow-collector-worker.ts" : "./traffic-flow-collector-worker.js",
|
||||
ts ? "./traffic-flow-worker-bootstrap.mjs" : "./traffic-flow-collector-worker.js",
|
||||
import.meta.url,
|
||||
)
|
||||
}
|
||||
@@ -125,7 +125,7 @@ async function spawnWorker(): Promise<void> {
|
||||
await applyExporterCtxFromDb()
|
||||
const exporterMap = await buildExporterMapPayload()
|
||||
if (databaseStop) return
|
||||
const w = new Worker(workerFileUrl(), { execArgv: process.execArgv })
|
||||
const w = new Worker(trafficFlowWorkerFileUrl(), { execArgv: process.execArgv })
|
||||
w.on("message", (msg: WorkerToMain) => handleWorkerMessage(msg))
|
||||
w.on("error", (err) => {
|
||||
state = { bound: false, address: null }
|
||||
|
||||
@@ -100,7 +100,10 @@ if (!ownDb) {
|
||||
await new Promise<void>(resolve => reservation.bind(0, "127.0.0.1", resolve))
|
||||
const port = reservation.address().port
|
||||
await new Promise<void>(resolve => reservation.close(resolve))
|
||||
const workerFile = new URL(import.meta.url.endsWith(".ts") ? "./traffic-flow-collector-worker.ts" : "./traffic-flow-collector-worker.js", import.meta.url)
|
||||
const { trafficFlowWorkerFileUrl } = await import("./traffic-flow-ingest.js")
|
||||
const workerFile = process.env.MMAPP_TEST_COMPILED_WORKER === "true"
|
||||
? new URL("../../dist/services/traffic-flow-collector-worker.js", import.meta.url)
|
||||
: trafficFlowWorkerFileUrl()
|
||||
worker = new Worker(workerFile)
|
||||
worker.on("error", error => { workerError = error })
|
||||
worker.on("message", (message: WorkerToMain) => {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// Register the TypeScript resolver inside this worker; parent hooks are not enough.
|
||||
import { tsImport } from "tsx/esm/api"
|
||||
|
||||
await tsImport(new URL("./traffic-flow-collector-worker.ts", import.meta.url).href, import.meta.url)
|
||||
Reference in new issue
Block a user