vnews 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vnews/config.rb +10 -2
- data/lib/vnews/folder.rb +10 -4
- data/lib/vnews/opml.rb +16 -9
- data/lib/vnews/version.rb +1 -1
- metadata +2 -2
data/lib/vnews/config.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'vnews/sql'
|
2
2
|
require 'yaml'
|
3
3
|
require 'thread_pool'
|
4
|
+
require 'vnews/constants'
|
5
|
+
require 'timeout'
|
4
6
|
|
5
7
|
class Vnews
|
6
8
|
def self.sql_client
|
@@ -86,12 +88,18 @@ class Vnews
|
|
86
88
|
puts "Adding feeds: #{(new_feeds - old_feeds).inspect}"
|
87
89
|
puts "Adding folder-feed associations: #{(ff - old_ff).inspect}"
|
88
90
|
feeds2 = []
|
89
|
-
pool = ThreadPool.new
|
91
|
+
pool = ThreadPool.new Vnews::POOLSIZE
|
90
92
|
puts "Using thread pool size of 10"
|
91
93
|
# TODO sometimes feeds are downloaded twice;
|
92
94
|
ff.each do |feed_url, folder|
|
93
95
|
pool.process do
|
94
|
-
|
96
|
+
begin
|
97
|
+
Timeout::timeout(Vnews::TIMEOUT) do
|
98
|
+
feeds2 << Vnews::Feed.fetch_feed(feed_url, folder)
|
99
|
+
end
|
100
|
+
rescue Timeout::Error
|
101
|
+
puts "TIMEOUT ERROR: #{feed_url}"
|
102
|
+
end
|
95
103
|
end
|
96
104
|
end
|
97
105
|
pool.join
|
data/lib/vnews/folder.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'vnews/feed'
|
2
2
|
require 'thread_pool'
|
3
|
+
require 'vnews/constants'
|
3
4
|
|
4
5
|
class Vnews
|
5
6
|
class Folder
|
@@ -12,12 +13,17 @@ class Vnews
|
|
12
13
|
folder = Vnews::Display.strip_item_count(folder)
|
13
14
|
puts "Updating folder: #{folder.inspect}"
|
14
15
|
feeds = []
|
15
|
-
pool = ThreadPool.new
|
16
|
-
puts "Using thread pool size of
|
16
|
+
pool = ThreadPool.new Vnews::POOLSIZE
|
17
|
+
puts "Using thread pool size of #{Vnews::POOLSIZE}"
|
17
18
|
Vnews.sql_client.feeds_in_folder(folder.strip).each do |feed|
|
18
19
|
pool.process do
|
19
|
-
|
20
|
-
|
20
|
+
begin
|
21
|
+
Timeout::timeout(Vnews::TIMEOUT) do
|
22
|
+
feeds << Vnews::Feed.fetch_feed(feed, folder)
|
23
|
+
end
|
24
|
+
rescue Timeout::Error
|
25
|
+
puts "TIMEOUT ERROR: #{feed_url}"
|
26
|
+
end
|
21
27
|
end
|
22
28
|
end
|
23
29
|
pool.join
|
data/lib/vnews/opml.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'vnews/feed'
|
3
|
+
require 'vnews/constants'
|
3
4
|
|
4
5
|
class Vnews
|
5
6
|
class Opml
|
@@ -11,18 +12,24 @@ class Vnews
|
|
11
12
|
doc = Nokogiri::XML.parse(opml)
|
12
13
|
feeds = []
|
13
14
|
doc.xpath('/opml/body/outline').each_slice(CONCURRENCY) do |xs|
|
14
|
-
pool = ThreadPool.new
|
15
|
-
puts "Using thread pool size of
|
15
|
+
pool = ThreadPool.new Vnews::POOLSIZE
|
16
|
+
puts "Using thread pool size of #{Vnews::POOLSIZE}"
|
16
17
|
xs.each do |n|
|
17
18
|
pool.process do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
begin
|
20
|
+
Timeout::timeout(Vnews::TIMEOUT) do
|
21
|
+
if n.attributes['xmlUrl']
|
22
|
+
feeds << Vnews::Feed.fetch_feed(n.attributes['xmlUrl'].to_s)
|
23
|
+
else
|
24
|
+
folder = n.attributes["title"].to_s
|
25
|
+
$stderr.print "Found folder: #{folder}\n"
|
26
|
+
n.xpath("outline[@xmlUrl]").each do |m|
|
27
|
+
feeds << Vnews::Feed.fetch_feed(m.attributes['xmlUrl'].to_s, folder)
|
28
|
+
end
|
29
|
+
end
|
25
30
|
end
|
31
|
+
rescue Timeout::Error
|
32
|
+
puts "TIMEOUT ERROR: #{feed_url}"
|
26
33
|
end
|
27
34
|
end
|
28
35
|
end
|
data/lib/vnews/version.rb
CHANGED