Closed ash-vd closed 2 years ago
I'll have to take a closer look at this when I'm at my computer but I don't think that is a valid job declaration. I think that job creation should throw an error since I do not think the function it is returning could be called. Try removing the export and just calling console in the file then pass the file path in job config.
Thanks @shadowgate15. I've tried to change the file to your suggestion, but unfortunately that doesn't resolve my issue. I've updated the demo-repository as well.
So I have figured out the problem. It is an issue with NX. Basically NX hijacks Module._load
to handle the require mappings. It does this by forking and actually running a file to grab the module that overwrites the Module._load
then requiring the file that should be run. This is never passed on to the Worker
since it is a new process. I will make an issue with NX and then post the link here so we can track it.
As a work around:
{
name: 'job',
path: path.join(
process.cwd(),
'node_modules',
'@nrwl/js/src/executors/node/node-with-require-overrides.js'
),
worker: {
env: {
...process.env,
NX_FILE_TO_RUN: path.join(__dirname, 'jobs/job.js'),
},
},
}
Jobs can be setup like this and they work. Basically, it recreates the code NX is doing, definitely not pretty. Hopefully, NX will come up with a solution or we can create a plugin for this, eventually.
Thank you very much @shadowgate15! At least I can continue now :).
For sure, this is definitely a core bug in NX since it breaks worker_threads
.
I'm still facing some issues with this approach. If I use the js:tsc
executor I'm not able to create a Docker container from the build, as there is no option to generate a package.json
with this executor. When I try to switch to the node:build
executor, the jobs folder isn't bundled, and bree can't find that folder.
Would it be possible to import the jobs into index.ts
with the solution you proposed, as I did in my first example? That way webpack would compile the jobs-folder as well.
That fix is just for the js:node
executor. You won't be able to import them into index.ts
and use them the way you did because of the way worker_threads
. It is a hard limitation of node.
You should be able to specify the files that are bundled in the NX
configs somewhere. which should resolve the problem. There also maybe a better way to define the path for webpack. You could also copy the code from that file the path is pointed to into your code base and use that file. Also take a look at how we define the worker
in ts-worker
, which could make it easier for you to setup the jobs.
I'd like to run Bree as part of a monorepo. Eventually this application should be able to be ran in a Docker container. I've setup Bree as an application (
apps/application
), in which I would like to load a library (libs/lib
). In the root of the application (index.ts
) this library is available, but it isn't found injobs/job.ts
. My guess is that it has something to do with the workers that Bree uses, but I haven't found anything related to my problem.The error I get when I run
nx serve application
is:I've setup a demo repository, but I'll also post some relevant files here:
app/apps/project.json
:app/application/src/index.ts
apps/application/jobs/job.ts
I also posted this question on StackOverflow.
Checklist