cluster-requiem
Enhacements for the cluster
module in order to handle graceful shutdowns with jobs that aren't associated with a socket.
History
Node cluster
modules garantees that all server sockets will be closed before exiting the process, but this doesn't extends to all other jobs that can't be interrupted.
This makes the cluster
module useless when combined with softwares like PM2 as long standing jobs that don't have a client requets associated with it will die when you reload the server.
This module solves this by adding trackers
which holds the server up until all they finishes their jobs.
Usage
Install it
npm install --save cluster-requiem
Initialize and prepare servers
var http = ;var cluster = ;var requiem = ; if clusterisMaster var worker = cluster; ; else var { ; }; requiem; requiem; var server = http; requiem; server; requiem; console
Note: You need to track server sockets in case of a graceful shutdown(PM2 for instance, sends the 'shutdown' event before trying to kill the process). If you don't do this the server will stil receive connections while it waits for all trackers to finish. Under high load this will potentially lead the server to never close, making PM2 kill long standing jobs as it can't handle they.