vnews 0.3.5 → 0.3.6

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.
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(10)
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
- feeds2 << Vnews::Feed.fetch_feed(feed_url, folder)
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(10)
16
- puts "Using thread pool size of 10"
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
- sleep(rand(10))
20
- feeds << Vnews::Feed.fetch_feed(feed, folder)
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(10)
15
- puts "Using thread pool size of 10"
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
- if n.attributes['xmlUrl']
19
- feeds << Vnews::Feed.fetch_feed(n.attributes['xmlUrl'].to_s)
20
- else
21
- folder = n.attributes["title"].to_s
22
- $stderr.print "Found folder: #{folder}\n"
23
- n.xpath("outline[@xmlUrl]").each do |m|
24
- feeds << Vnews::Feed.fetch_feed(m.attributes['xmlUrl'].to_s, folder)
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
@@ -1,4 +1,4 @@
1
1
  class Vnews
2
- VERSION = '0.3.5'
2
+ VERSION = '0.3.6'
3
3
  end
4
4
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 5
9
- version: 0.3.5
8
+ - 6
9
+ version: 0.3.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Choi