Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Attempting to access worker data within a function job throws worker_threads_1 is not defined #246

Open
3 tasks done
Gmanicus opened this issue Mar 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Gmanicus
Copy link

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.
@Gmanicus Gmanicus added the bug Something isn't working label Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant