Commit 833e001202e00dccf0709b670c0df231b0bac97f
Exists in
staging
and in
37 other branches
Merge branch 'fix-feed-never-fetched' into 'master'
Fix feed that has never been fetched succesfully This avoid a crash when container.fetched_at is `nil`. See merge request !782
Showing
2 changed files
with
17 additions
and
1 deletions
Show diff stats
lib/feed_handler.rb
... | ... | @@ -53,7 +53,7 @@ class FeedHandler |
53 | 53 | def process(container) |
54 | 54 | begin |
55 | 55 | container.class.transaction do |
56 | - if container.update_errors > FeedHandler.max_errors && container.fetched_at < (Time.now - FeedHandler.disabled_period) | |
56 | + if failed_too_many_times(container) && enough_time_since_last_failure(container) | |
57 | 57 | container.enabled = true |
58 | 58 | container.update_errors = 0 |
59 | 59 | container.save |
... | ... | @@ -103,4 +103,12 @@ class FeedHandler |
103 | 103 | url =~ URI.regexp('http') || url =~ URI.regexp('https') |
104 | 104 | end |
105 | 105 | |
106 | + def failed_too_many_times(container) | |
107 | + container.update_errors > FeedHandler.max_errors | |
108 | + end | |
109 | + | |
110 | + def enough_time_since_last_failure(container) | |
111 | + container.fetched_at.nil? || container.fetched_at < (Time.now - FeedHandler.disabled_period) | |
112 | + end | |
113 | + | |
106 | 114 | end | ... | ... |
test/unit/feed_handler_test.rb
... | ... | @@ -132,6 +132,14 @@ class FeedHandlerTest < ActiveSupport::TestCase |
132 | 132 | |
133 | 133 | assert container.enabled, 'must reenable container after <disabled_period> (%s)' % container_class |
134 | 134 | end |
135 | + | |
136 | + should "handle a feed that was never fetched successfully (#{container_class})" do | |
137 | + container = create(container_class) | |
138 | + container.update_errors = FeedHandler.max_errors + 1 | |
139 | + container.fetched_at = nil | |
140 | + handler.expects(:actually_process_container).with(container) | |
141 | + handler.process(container) | |
142 | + end | |
135 | 143 | end |
136 | 144 | |
137 | 145 | should 'not crash even when finish fetch fails' do | ... | ... |