Background
In packages/jobs/src/bins/rw-jobs.ts, the signalSetup function (line 187) only sets up a handler for SIGINT (Ctrl+C):
process.on('SIGINT', () => {
// forwards SIGINT to each worker for graceful shutdown
workers.forEach(worker => worker.kill('SIGINT'))
})
There is a TODO at line 150 noting that SIGTERM/SIGKILL support is missing:
// TODO add support for stopping with SIGTERM or SIGKILL?
export const stopWorkers = async ({ ... signal = 'SIGINT', ... }) => { ... }
SIGTERM is the standard signal sent by Docker, Kubernetes, and systemd when stopping a container or service. Without a SIGTERM handler in the parent process, the job runner ignores graceful shutdown requests from container orchestration — workers may be hard-killed without finishing their current job.
What needs to be done
Add a SIGTERM handler in signalSetup that forwards graceful shutdown to workers, mirroring the SIGINT behavior:
// SIGTERM: sent by Docker, systemd, Kubernetes during shutdown
process.on('SIGTERM', () => {
logger.info('SIGTERM received: shutting down workers gracefully...')
workers.forEach((worker) => {
worker.kill('SIGTERM')
})
})
This ensures that when the container/service is stopped, in-progress jobs get a chance to complete or be re-queued rather than being abruptly killed.
Additional consideration
The stop command in main() currently always uses SIGINT:
case 'stop':
return await stopWorkers({ numWorkers, signal: 'SIGINT', logger })
Consider adding a --signal flag to the CLI so operators can choose SIGTERM for deployment scenarios.
File
packages/jobs/src/bins/rw-jobs.ts, lines 150 and 187–220
Background
In
packages/jobs/src/bins/rw-jobs.ts, thesignalSetupfunction (line 187) only sets up a handler forSIGINT(Ctrl+C):There is a TODO at line 150 noting that
SIGTERM/SIGKILLsupport is missing:SIGTERMis the standard signal sent by Docker, Kubernetes, and systemd when stopping a container or service. Without aSIGTERMhandler in the parent process, the job runner ignores graceful shutdown requests from container orchestration — workers may be hard-killed without finishing their current job.What needs to be done
Add a
SIGTERMhandler insignalSetupthat forwards graceful shutdown to workers, mirroring the SIGINT behavior:This ensures that when the container/service is stopped, in-progress jobs get a chance to complete or be re-queued rather than being abruptly killed.
Additional consideration
The
stopcommand inmain()currently always usesSIGINT:Consider adding a
--signalflag to the CLI so operators can chooseSIGTERMfor deployment scenarios.File
packages/jobs/src/bins/rw-jobs.ts, lines 150 and 187–220