Open
Description
Describe the bug
Node.js version: 18
OS version: Ubuntu (Docker)
Description: After discovering that class functions cannot be used for the scheduler jobs, I created a top-level function and am attempting to access the workerData
to run the correct Collector (see #245).
function runCollectorJob() {
console.log(workerData)
const { datasource }: { datasource: string } = workerData;
getCollector(datasource).runJob()
}
// ...elsewhere
... await this.scheduler.add({
name: options.name,
path: runCollectorJob,
worker: {
name: options.name,
workerData: {
datasource: options.name,
}
}
});
[worker eval]:3
console.log(worker_threads_1.workerData);
^
ReferenceError: worker_threads_1 is not defined
at runCollectorJob ([worker eval]:3:17)
at [worker eval]:9:3
at runScriptInThisContext (node:internal/vm:143:10)
at node:internal/process/execution:100:14
at [worker eval]-wrapper:6:24
at runScript (node:internal/process/execution:83:62)
at evalScript (node:internal/process/execution:114:10)
at MessagePort.<anonymous> (node:internal/main/worker_thread:166:9)
at MessagePort.[nodejs.internal.kHybridDispatch] (node:internal/event_target:786:20)
at MessagePort.exports.emitMessage (node:internal/per_context/messageport:23:28)
Code to reproduce
I can create a sample reproduction of the problem if needed.
Checklist
- I have searched through GitHub issues for similar issues.
- I have completely read through the README and documentation.
- I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.