>> On Monday, December 8, 2014 at 3:47 PM, Ω Alisson wrote: >> >> I'm running a Node app that fetches Redis data into another database. It´s >> using the cluster module, everything works fine but I need to ensure that >> workers will finish properly their jobs(they use BRPOP then allocate into a >> object then insert in batches cleaning the objects), how do I do this?
On Tue, Dec 9, 2014 at 7:33 AM, Ω Alisson <[email protected]> wrote: > if I do something like this on a worker process, wouldn't be effective? > > process.on("message", function(m) { > if(m.cmd === "disconnect") { > // cleanup logic > } > }) If I understand correctly, you want workers to be given a chance to finish what they are doing when disconnected using node cluster? In principle this works, though that message doesn't exist (unless you send it?). You don't say how/when you fork and/or disconnect workers. Generally, this would happen in gracefull shutdown by calling `cluster.disconnect()` in the node master. Unfortunately, while that waits for cluster worker ***servers*** to close, it doesn't wait for clients, like redis clients. LIke yours, likely. You can trap the disconnect message if you are willing to use node internals: https://gist.github.com/sam-github/8185222 node cluster should really expose that event, IMO, but so it goes, for the moment. Most supervisors, strongloops's included, offer a way to inform the worker that it should cleanup. `slc run` sends a shutdown message, https://github.com/strongloop/strong-cluster-control/blob/master/api.md#controlcmdshutdown, for example, when shutting down, and gives 60seconds grace to the worker (configurable), before SIGTERMing it. Cheers, Sam -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CACmrRmSaa5hb6zSwSP6Z8YX7PdifXxnE-%2BsZdbosVDmgXOegrw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
