Skip to content

Instantly share code, notes, and snippets.

View EdJ's full-sized avatar

Ed EdJ

View GitHub Profile
@EdJ
EdJ / app.js
Created December 3, 2013 11:56
Example of an inability to have a unified zero-downtime deployment method when using node.js's cluster module with non-net servers. This causes an issue when using a PULL-based server, for example, when using a RabbitMQ component service. Obviously there are ways around this problem, but a unified method would be nice.
var Application = function Application() {
this.value = Math.random().toFixed(2);
console.log('Worker switched to value ' + this.value);
this.handleRequest = function (r, rs) {
console.log('Worker returning value ' + this.value);
rs.end(this.value.toString());
};
};
@EdJ
EdJ / gist:6293376
Last active December 21, 2015 10:39
Basic event emitting demonstration, showing the in-worker emits, but not the ability to emit beyond the worker boundary. This prevents me manually triggering the 'listening' event that a net.Server emits when it opens, and therefore stops me doing hot-patching when releasing in the same manner between a front-end webserver and a backend RabbitMQ…
var cluster = require('cluster');
if (cluster.isMaster) {
var worker = cluster.fork();
worker.on('test', function() {
console.log('worker is listening');
});
} else {
process.on('test', function() {