From 2bac20f2e45d20e4724b8eea20d195ec2dfce75c Mon Sep 17 00:00:00 2001 From: Tjatse Date: Wed, 17 Dec 2014 11:24:45 +0800 Subject: [PATCH] fix: process awake from sleeping --- lib/mon.js | 1 + lib/pm.js | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/mon.js b/lib/mon.js index a0502c5..6886636 100644 --- a/lib/mon.js +++ b/lib/mon.js @@ -358,6 +358,7 @@ Monitor.prototype._startWatching = function(){ this._throttleRefresh(); }.bind(this)); + // Enforce a refresh operation if RPC is not online. this._throttleRefresh(); }; diff --git a/lib/pm.js b/lib/pm.js index 79b9f48..517b017 100644 --- a/lib/pm.js +++ b/lib/pm.js @@ -26,9 +26,18 @@ pm.sub = function(sockPath, cb){ var sub = axon.socket('sub-emitter'), sub_sock = sub.connect(sockPath); - sub.on('process:*', function(event, data){ - if (data && !!~allowedEvents.indexOf(data.event)) { - cb(data); + // Once awake from sleeping. + sub.on('log:*', function(e, d){ + // Do not subscribe it. + sub.off('log:*'); + d.event = 'awake'; + cb(d); + }); + + // Process events. + sub.on('process:*', function(e, d){ + if (d && !!~allowedEvents.indexOf(d.event)) { + cb(d); } }); };