I have 2 tiny node services:
1. screenshot service 
(https://github.com/fzaninotto/screenshot-as-a-service) - get's url and can 
stream back a snapshop of it.
2. image updater - calls the screenshot service every few minutes with 5 
urls.

Here is the code for the image updater.

require('http');
var url  = require('url');
var fs   = require('fs');
var environment = process.env.NODE_ENV || 'development';
var config = require('./config/' + environment + '.js');
var interval = config.interval * 1000 * 60; //we want minutes

function createImages(){ 
  console.log(new Date().toUTCString(), ' - creating images');
  for (name in config.urls) {
    var options = url.parse(config.screenshotServiceUrl + 
config.urls[name]);
    createImage(name, options);
  };
}

// get request to our screenshot service and creating an image file
function createImage(name, options) {
  http.get(options, function(res) {
    var stream = fs.createWriteStream(config.imagesPath + name + '.png');

    res.on('data', function (chunk) {
      stream.write(chunk);
    });

    res.on('end', function (chunk) {
      stream.end();
    });
  });
};

createImages();

// every 5 minutes
setInterval(function() {
  createImages();
}, interval);

After a few hours (maybe days sometimes) of running them, I have one out of 
the following 2 issues - 
1. The image updater crashes with this message: 'Error: socket hang up'.
2. The machine is getting slow since there are multiple instances of 
phantomjs, the tool used by the screenshot service. I have to manualy kill 
them (ps aux|grep phantomjs | awk '{print $2}' xargs kill -9).

my node version - 0.6.14
google for the first issue led me to this discussion - 
https://groups.google.com/forum/#!topic/nodejs/kYnfJZeqGZ4 but it seems to 
be an old version of node.

Any tips and ideas ore welcome!

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to