Commit 4f9a5daf6ce4e454086bf9b9a989ac907c908fb4
1 parent
27d41c7f
Exists in
master
and in
29 other branches
Reenable Feed after a period disabled
Reenable a feed that was disabled due to reaching a max number of errors after a max period being disabled, e.x. 1 week I had to change the FeedUpdate for this, since I had to inclued the feeds with enabled == false to check for their disabled period. (ActionItem2277)
Showing
3 changed files
with
26 additions
and
1 deletions
Show diff stats
lib/feed_handler.rb
@@ -17,8 +17,10 @@ class FeedHandler | @@ -17,8 +17,10 @@ class FeedHandler | ||
17 | 17 | ||
18 | # The maximum number | 18 | # The maximum number |
19 | cattr_accessor :max_errors | 19 | cattr_accessor :max_errors |
20 | + cattr_accessor :disabled_period | ||
20 | 21 | ||
21 | self.max_errors = 6 | 22 | self.max_errors = 6 |
23 | + self.disabled_period = 1.week | ||
22 | 24 | ||
23 | def parse(content) | 25 | def parse(content) |
24 | raise FeedHandler::ParseError, "Content is nil" if content.nil? | 26 | raise FeedHandler::ParseError, "Content is nil" if content.nil? |
@@ -52,6 +54,12 @@ class FeedHandler | @@ -52,6 +54,12 @@ class FeedHandler | ||
52 | RAILS_DEFAULT_LOGGER.info("Processing %s with id = %d" % [container.class.name, container.id]) | 54 | RAILS_DEFAULT_LOGGER.info("Processing %s with id = %d" % [container.class.name, container.id]) |
53 | begin | 55 | begin |
54 | container.class.transaction do | 56 | container.class.transaction do |
57 | + if container.update_errors > FeedHandler.max_errors && container.fetched_at < (Time.now - FeedHandler.disabled_period) then | ||
58 | + container.enabled = true | ||
59 | + container.update_errors = 0 | ||
60 | + container.save | ||
61 | + end | ||
62 | + next unless container.enabled | ||
55 | actually_process_container(container) | 63 | actually_process_container(container) |
56 | container.update_errors = 0 | 64 | container.update_errors = 0 |
57 | container.finish_fetch | 65 | container.finish_fetch |
@@ -63,6 +71,7 @@ class FeedHandler | @@ -63,6 +71,7 @@ class FeedHandler | ||
63 | container.update_errors += 1 | 71 | container.update_errors += 1 |
64 | container.error_message = exception.to_s | 72 | container.error_message = exception.to_s |
65 | if container.update_errors > FeedHandler.max_errors | 73 | if container.update_errors > FeedHandler.max_errors |
74 | + container.fetched_at = Time.now | ||
66 | container.enabled = false | 75 | container.enabled = false |
67 | end | 76 | end |
68 | begin | 77 | begin |
lib/feed_updater.rb
test/unit/feed_handler_test.rb
@@ -112,6 +112,22 @@ class FeedHandlerTest < ActiveSupport::TestCase | @@ -112,6 +112,22 @@ class FeedHandlerTest < ActiveSupport::TestCase | ||
112 | assert !container.error_message.blank?, 'must set error message in container after <max_errors> errors (%s)' % container_class | 112 | assert !container.error_message.blank?, 'must set error message in container after <max_errors> errors (%s)' % container_class |
113 | assert !container.enabled, 'must disable continer after <max_errors> errors (%s)' % container_class | 113 | assert !container.enabled, 'must disable continer after <max_errors> errors (%s)' % container_class |
114 | end | 114 | end |
115 | + | ||
116 | + should "reenable after <disabled_period> (#{container_class})" do | ||
117 | + FeedHandler.stubs(:max_errors).returns(4) | ||
118 | + | ||
119 | + container = create(container_class) | ||
120 | + handler.stubs(:actually_process_container).with(container).raises(Exception.new("crash")) | ||
121 | + # exceeds max_errors | ||
122 | + 5.times { handler.process(container) } | ||
123 | + | ||
124 | + # after disabled period, tries to process the container again | ||
125 | + last_error = Time.now | ||
126 | + Time.stubs(:now).returns(last_error + FeedHandler.disabled_period + 1.second) | ||
127 | + handler.process(container) | ||
128 | + | ||
129 | + assert container.enabled, 'must reenable container after <disabled_period> (%s)' % container_class | ||
130 | + end | ||
115 | end | 131 | end |
116 | 132 | ||
117 | should 'not crash even when finish fetch fails' do | 133 | should 'not crash even when finish fetch fails' do |