blinkr 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/blinkr/extensions/links.rb +2 -1
- data/lib/blinkr/phantomjs_wrapper.rb +28 -26
- data/lib/blinkr/snap.js +3 -4
- data/lib/blinkr/typhoeus_wrapper.rb +4 -0
- data/lib/blinkr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6d0248a7f8b5ffd6fb131c9bfd554d542fcf4e2
|
4
|
+
data.tar.gz: cc36b93643ea59c8b2874f31fbec41f0460a353b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
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
|
-
|
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 ===
|
6
|
-
console.log('Usage: snap.js <URL> <view port width>
|
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
|
-
|
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
|
data/lib/blinkr/version.rb
CHANGED
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.
|
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
|
+
date: 2015-08-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|