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-build
Or to watch source files:
npm run workers-watch
Then to run the worker:
npm run workers-start
@koolamusic
I didn't explain it well, but I'm using Google Cloud Run for serving Next.js web traffic and Google Compute Engine to run a worker. I manually SSH to the worker to run it similar to how I run it locally here.