worker.js
* Multi-Threading High Availability Application Worker
* @module greppy/app/cluster/worker
* @author Hermann Mayer <hermann.mayer92@gmail.com>
var extend = require('extend');
var AppWorker = require('../worker');
var WorkerIPC = require('./worker/ipc');
var IPCLogger = require('./worker/ipc/logger');
* @param {Object} options - Options object
* @param {Function} callback - Function to call on finish
var Worker = function(options, callback)
// Setup the IPC logger transport
var part = moment().format().yellow.bold;
part += ' [Worker]'.white.bold;
// Extend the given worker configuration
arguments[0] = extend(true, workerConf, arguments[2] || {});
Worker.super_.call(this, options);
* Extend Greppy framework single threading worker
util.inherits(Worker, AppWorker);
* @param {Object} app - Express application object
* @param {Object} server - HTTP(S) server object
* @param {Function} callback - Function to call on finish
Worker.prototype.configure = function(app, server, callback)
var setupWorker = function(callback)
self.ipc.addBroadcastListener('gracefull.shutdown', function() {
// Quick shutdown for the debugging mode
if (self.cliArgs.options.debug) {
logger.info('HTTP server went offline - not accepting connections anymore');
logger.info('Closed all backend connections');
// Shutdown the process, without errors
// Annotate the worker context to the master via IPC
self.getIPC().request('worker.annotateContext', self.context);
Worker.super_.prototype.configure.call(this, app, server, function() {
* Get the worker IPC implementation object.
* @return {Object} The IPC Object