An example of how to add a background task (e.g. a queue consumer) to an existing NextJS project.
- Add your background task file
- Add a new
worker-tsconfig.json, specifically specifying"module": "commonjs"and targeting only the worker source files. - Add convenience functions for building & running to
package.json
Then to build once:
npm run workers-buildOr to watch source files:
npm run workers-watchThen to run the worker:
npm run workers-start
I read through your docker file and I am finding it hard to makes sense of how you are running your server.
My understanding is that I can use a simple
Dockerfileto run the Next app with the worker task running in the background.however, it seems like there are are couple more features in your code that isn't reflected here.