blinkr 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f3dba6e6e0d389b3760f1f8e5fed683f52f93bd
4
- data.tar.gz: bf28ba4b5e000d6492429e92409a97434e628106
3
+ metadata.gz: e6d0248a7f8b5ffd6fb131c9bfd554d542fcf4e2
4
+ data.tar.gz: cc36b93643ea59c8b2874f31fbec41f0460a353b
5
5
  SHA512:
6
- metadata.gz: 3ade22d86f835fe6addb8262bd416d3f8cd797ba342aa447b7bd6ff76080229a81189b56538c789de67e1bd1461a57657c6c11075571ef0820bec19bc746b670
7
- data.tar.gz: 819b85bfc6f8fd85ccd13040a0cb3832444a7019f97f5b16f4fa402f26694f996dbe3bfdd414127e002d996837b809b40a9f9434c4d44ef4062c994070605f02
6
+ metadata.gz: a48ff2eb5cc0d25694bc17f6d34c7443199cf4521bd6564e21f197e99bc0d39d6ced7a4169049ff32f6f72c163b771914bd60f298b491b8d873f169cbb70f0ae
7
+ data.tar.gz: 521419f058076d99248ed4bf0642a5be3152ad7d698f0089e0d5bf6031d1e8b7f1544b2279712437f2c36ce91008591978aa7d81bf5099ea41e507d77afeb9d6
@@ -59,7 +59,8 @@ module Blinkr
59
59
  end
60
60
  external_links.each do |url, metadata|
61
61
  # if link start_with? @config.base_url check to see if it's in the sitemap.xml
62
- browser.process(url, @config.max_retrys, :method => :get, :followlocation => true) do |resp|
62
+ browser.process(url, @config.max_retrys, :method => :get, :followlocation => true, :timeout => 30,
63
+ :connecttimeout => 10, :maxredirs => 3) do |resp|
63
64
  puts "Loaded #{url} via #{browser.name} #{'(cached)' if resp.cached?}" if @config.verbose
64
65
 
65
66
  if resp.code.to_i < 200 || resp.code.to_i > 300
@@ -4,6 +4,7 @@ require 'tempfile'
4
4
  require 'blinkr/http_utils'
5
5
  require 'blinkr/cache'
6
6
  require 'parallel'
7
+ require 'open3'
7
8
 
8
9
  module Blinkr
9
10
  class PhantomJSWrapper
@@ -39,38 +40,39 @@ module Blinkr
39
40
  def _process url, limit, max, opts = {}, &block
40
41
  raise "limit must be set. url: #{url}, limit: #{limit}, max: #{max}" if limit.nil?
41
42
  unless @config.skipped? url
42
- Tempfile.open('blinkr') do|f|
43
- # Try and sidestep any unnecessary requests by checking the cache
44
- request = Typhoeus::Request.new(url)
45
- if @cache.get(request)
46
- return block.call response, @cache.get("#{url}-resourceErrors"), @cache.get("#{url}-javascriptErrors")
47
- end
43
+ #Tempfile.open('blinkr') do|f|
44
+ # Try and sidestep any unnecessary requests by checking the cache
45
+ request = Typhoeus::Request.new(url)
46
+ if @cache.get(request)
47
+ return block.call response, @cache.get("#{url}-resourceErrors"), @cache.get("#{url}-javascriptErrors")
48
+ end
48
49
 
49
- if system "phantomjs #{SNAP_JS} #{url} #{@config.viewport} #{f.path}"
50
- json = JSON.load(File.read(f.path))
51
- response = Typhoeus::Response.new(:code => 200, :body => json['content'], :effective_url => json['url'],
50
+ output, status = Open3.capture2("phantomjs #{SNAP_JS} #{url} #{@config.viewport}")
51
+ if status == 0
52
+ json = JSON.load(output)
53
+ response = Typhoeus::Response.new(:code => 200, :body => json['content'], :effective_url => json['url'],
54
+ :mock => true)
55
+ response.request = Typhoeus::Request.new(url)
56
+ Typhoeus.stub(url).and_return(response)
57
+ @cache.set(response.request, response)
58
+ @cache.set("#{url}-resourceErrors", json['resourceErrors'])
59
+ @cache.set("#{url}-javascriptErrors", json['javascriptErrors'])
60
+ block.call response, json['resourceErrors'], json['javascriptErrors']
61
+ else
62
+ if limit > 1
63
+ puts "Loading #{url} via phantomjs (attempt #{max - limit + 2} of #{max})" if @config.verbose
64
+ _process url, limit - 1, max, &block
65
+ else
66
+ puts "Loading #{url} via phantomjs failed" if @config.verbose
67
+ response = Typhoeus::Response.new(:code => 0, :status_message => "Server timed out after #{max} retries",
52
68
  :mock => true)
53
69
  response.request = Typhoeus::Request.new(url)
54
70
  Typhoeus.stub(url).and_return(response)
55
71
  @cache.set(response.request, response)
56
- @cache.set("#{url}-resourceErrors", json['resourceErrors'])
57
- @cache.set("#{url}-javascriptErrors", json['javascriptErrors'])
58
- block.call response, json['resourceErrors'], json['javascriptErrors']
59
- else
60
- if limit > 1
61
- puts "Loading #{url} via phantomjs (attempt #{max - limit + 2} of #{max})" if @config.verbose
62
- _process url, limit - 1, max, &block
63
- else
64
- puts "Loading #{url} via phantomjs failed" if @config.verbose
65
- response = Typhoeus::Response.new(:code => 0, :status_message => "Server timed out after #{max} retries",
66
- :mock => true)
67
- response.request = Typhoeus::Request.new(url)
68
- Typhoeus.stub(url).and_return(response)
69
- @cache.set(response.request, response)
70
- block.call response, nil, nil
71
- end
72
+ block.call response, nil, nil
72
73
  end
73
- end
74
+ end
75
+ #end
74
76
  @count += 1
75
77
  end
76
78
  end
data/lib/blinkr/snap.js CHANGED
@@ -2,8 +2,8 @@ var system = require('system');
2
2
  var page = require('webpage').create();
3
3
  var fs = require('fs');
4
4
 
5
- if (system.args.length === 3) {
6
- console.log('Usage: snap.js <URL> <view port width> <out>');
5
+ if (system.args.length === 2) {
6
+ console.log('Usage: snap.js <URL> <view port width>');
7
7
  phantom.exit();
8
8
  }
9
9
 
@@ -13,7 +13,6 @@ info.javascriptErrors = [];
13
13
  info.url = system.args[1];
14
14
  info.view_port_width = system.args[2];
15
15
 
16
- var out = system.args[3]
17
16
  var current_requests = 0;
18
17
  var last_request_timeout;
19
18
  var final_timeout;
@@ -75,7 +74,7 @@ var exit = function exit(err_code) {
75
74
  info.content = page.content;
76
75
  // Re-read the URL in case we've been redirected
77
76
  info.url = page.url;
78
- fs.write(out, JSON.stringify(info), 'w');
77
+ system.stdout.write(JSON.stringify(info));
79
78
  if (err_code === undefined) {
80
79
  err_code = 0;
81
80
  }
@@ -2,6 +2,7 @@ require 'typhoeus'
2
2
  require 'blinkr/cache'
3
3
  require 'blinkr/http_utils'
4
4
  require 'net/http'
5
+ require 'logger'
5
6
 
6
7
  module Blinkr
7
8
  class TyphoeusWrapper
@@ -16,7 +17,10 @@ module Blinkr
16
17
  Typhoeus::Config.cache = Blinkr::Cache.new
17
18
  @hydra = Typhoeus::Hydra.new(:maxconnects => (@config.maxconnects || 30),
18
19
  :max_total_connections => (@config.maxconnects || 30),
20
+ :pipelining => false,
19
21
  :max_concurrency => (@config.maxconnects || 30))
22
+ Ethon.logger = Logger.new STDOUT if config.vverbose
23
+ Ethon::Curl.set_option(:max_host_connections, 5, @hydra.multi.handle, :multi)
20
24
  @count = 0
21
25
  @context = context
22
26
  end
@@ -1,4 +1,4 @@
1
1
  module Blinkr
2
- VERSION='0.3.2'
2
+ VERSION='0.3.3'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blinkr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Muir
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-12 00:00:00.000000000 Z
12
+ date: 2015-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler