From f5c54abab9433a8df5db72a9f1adf97dcc2b9d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gonz=C3=A0lez=20Lareo?= Date: Thu, 23 Jan 2014 14:21:34 +0100 Subject: [PATCH] Update README.md --- README.md | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 04b844b..7ec5aab 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # Express PhantomJS -A simple screenshot web service powered by [Express](http://expressjs.com) and [PhantomJS](http://www.phantomjs.org/). Basend on the project [screenshot-as-service](https://github.com/fzaninotto/screenshot-as-a-service) but with multiple phantomjs servers and a redis bd to save the work charge of the phantomjs servers. +This project was started as a screenshot web service powered by [Express](http://expressjs.com) and [PhantomJS](http://www.phantomjs.org/). Basend on the project [screenshot-as-service](https://github.com/fzaninotto/screenshot-as-a-service) but with multiple phantomjs servers and a redis bd to save the work charge of the phantomjs servers. + +Now, this project is quite different. It's a cluster, of nodejs servers with a phantomjs executing as a moongose server (see the documentation of [phantomjs](http://www.phantomjs.org/)). This project use [Bull](https://github.com/OptimalBits/bull) as a internal job queue and [node-sidekiq](https://github.com/loopj/node-sidekiq) as a result queue. + +The node servers had the responsability to keep alive the phantomjs servers. ## Setup @@ -19,10 +23,33 @@ Express server listening on port 3000 ## Usage -For a quick test with the command line, type: +For a quick test insert a job in a bull queue as the exemple above: -```sh -$ curl http://localhost:3000/?address=www.google.com&output=/tmp/out.png&type=0 > output.png +``` +var queue = require('bull')("jobs_phantomjs", 6379, '127.0.0.1'); +var number = 100; +var lastJob = 0; + +// Lets create a few jobs for the queue workers +for (var i = 0; i < number; i++){ + var data = { + address: "http://www.google.com", + output: "/tmp/test.png", + type: 0 + }; + queue.add(data).then(function(job) { + console.log("Add job %s", job.jobId) + lastJob ++; + }, function(err){ + console.log("Error adding the job %s", job.jobId) + lastJob ++; + }); +} + +setInterval(function(){ + console.log("Added %s jobs", lastJob) + if (lastJob == number) { process.exit(1); } +},100); ``` ## Configuration @@ -32,20 +59,16 @@ Create a `config/development.yaml` or a `config/production.yaml` to override any ```yml rasterizer: command: phantomjs # phantomjs executable - port: 3001 # internal service port. No need to allow inbound or outbound access to this port + port: 3100 # internal service port. No need to allow inbound or outbound access to this port viewport: '612x612' # browser window size. Height frows according to the content - num: 1 +# num: 5 debug: false -cache: - lifetime: 60000 # one minute, set to 0 for no cache server: port: 3200 # main service port - useCors: false # enable CORS support - sendImage: false + loadTest: false redis: port: 6379 host: 127.0.0.1 - debug: false ``` For instance, if you want to setup a proxy for phantomjs, create a `config/development.yaml` as follows: @@ -53,4 +76,4 @@ For instance, if you want to setup a proxy for phantomjs, create a `config/devel ```yml rasterizer: command: 'phantomjs --proxy=myproxy:1234' -``` \ No newline at end of file +```