10 months ago
I have added multiple background worker scripts (email queue, token refresh, reply checker, payment retry, etc.) in package.json for a Next.js application. These workers are defined using tsx for development and compiled node scripts for production.
While the scripts are correctly configured in package.json, Railway appears to only run the default start command (npm run start) and does not automatically execute these worker processes.
I need clarification on:
- Whether Railway will run these worker scripts automatically
- If separate Railway services are required for each worker
- Or if a process manager (PM2) or Railway cron/jobs should be used instead
package.json
"scripts": { "build": "next build", "dev": "next dev", "lint": "next lint", "start": "next start", "build:workers": "tsc --project tsconfig.workers.json", "worker": "tsx workers/email-queue-worker.ts", "worker:prod": "node dist/workers/email-queue-worker.js", "token-refresh": "tsx workers/token-refresh-worker.ts", "token-refresh:prod": "node dist/workers/token-refresh-worker.js", "reply-checker": "tsx workers/reply-checker-worker.ts", "reply-checker:prod": "node dist/workers/reply-checker-worker.js", "payment-retry": "tsx workers/payment-retry-worker.ts", "payment-retry:prod": "node dist/workers/payment-retry-worker.js", "pm2:start": "pm2 start ecosystem.config.js", "pm2:stop": "pm2 stop ecosystem.config.js", "pm2:restart": "pm2 restart ecosystem.config.js", "pm2:logs": "pm2 logs", "pm2:status": "pm2 status" }
The goal is to ensure all background workers run reliably in production alongside the main Next.js application.
0 Replies