From 56b9babb5db799436c3b5d322f9bf6f6eca42714 Mon Sep 17 00:00:00 2001 From: david Date: Wed, 6 Nov 2013 14:56:13 +0100 Subject: [PATCH] When the phantomjs child process crash, correctly restart a child process for rendering --- lib/rasterizerService.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/rasterizerService.js b/lib/rasterizerService.js index 7e89860a..3ae1d123 100644 --- a/lib/rasterizerService.js +++ b/lib/rasterizerService.js @@ -4,6 +4,7 @@ var spawn = require('child_process').spawn; var request = require('request'); +var self; /** * Rasterizer service. @@ -26,7 +27,7 @@ var RasterizerService = function(config) { this.pingDelay = 10000; // every 10 seconds this.sleepTime = 30000; // three failed health checks, 30 seconds this.lastHealthCheckDate = null; - var self = this; + self = this; process.on('exit', function() { self.isStopping = true; self.killService(); @@ -47,7 +48,9 @@ RasterizerService.prototype.startService = function() { rasterizer.stdout.on('data', function (data) { console.log('phantomjs output: ' + data); }); - rasterizer.on('exit', this.rasterizerExitHandler); + rasterizer.on('exit', function() { + self.restartService(); + }); this.rasterizer = rasterizer; this.lastHealthCheckDate = Date.now(); this.pingServiceIntervalId = setInterval(this.pingService.bind(this), this.pingDelay);