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

transport options - either confusing variable names or I'm just still learning (free to admit it) #1911

Open
YeeP79 opened this issue Feb 28, 2024 · 1 comment

Comments

@YeeP79
Copy link

YeeP79 commented Feb 28, 2024

inside of the transport code, we have the base options object defined:

interface TransportBaseOptions<TransportOptions = Record<string, any>> {
        options?: TransportOptions
        worker?: WorkerOptions & { autoEnd?: boolean}
    }

follow the definition of workerOptions to node:

interface WorkerOptions {
        /**
         * List of arguments which would be stringified and appended to
         * `process.argv` in the worker. This is mostly similar to the `workerData`
         * but the values will be available on the global `process.argv` as if they
         * were passed as CLI options to the script.
         */
        argv?: any[] | undefined;
        env?: NodeJS.Dict<string> | typeof SHARE_ENV | undefined;
        eval?: boolean | undefined;
        workerData?: any;
        stdin?: boolean | undefined;
        stdout?: boolean | undefined;
        stderr?: boolean | undefined;
        execArgv?: string[] | undefined;
        resourceLimits?: ResourceLimits | undefined;
        /**
         * Additional data to send in the first worker message.
         */
        transferList?: TransferListItem[] | undefined;
        /**
         * @default true
         */
        trackUnmanagedFds?: boolean | undefined;
        /**
         * An optional `name` to be appended to the worker title
         * for debuggin/identification purposes, making the final title as
         * `[worker ${id}] ${name}`.
         */
        name?: string | undefined;
    }

Above I would think that if I plan to use the worker_threads library to access workerData, then I should be defining workerData as an element of worker inside the options for transport.

import { workerData } from 'node:worker_threads';

However, if we take a look at transport.js:

function transport (fullOptions) {
  const { pipeline, targets, levels, dedupe, options = {}, worker = {}, caller = getCallers() } = fullOptions

<snip>

  return buildStream(fixTarget(target), options, worker)
  <snip>

this leads me to believe that the thread will be built with my workerOptions...

function buildStream (filename, workerData, workerOpts) {
  const stream = new ThreadStream({
    filename,
    workerData,
    workerOpts
  })

BUT buildStream 're-names' options to workerData, but also passes 'workerOpts' which also has the element 'workerData' as shown above.

If you do import workerData you end up with what I would think are supposed to be the logger options passed to the transport.

Please correct me if I'm wrong, or at least explain how this is supposed to work and what the actual 'options' are meant to be.

Thank you.

@mcollina
Copy link
Member

I'm sorry but I don't understand what you are trying to achieve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants