Commit 30bcf28920e827aec3d8476e492843a047d360f3

Authored by Rodrigo Souto
1 parent 635a6c6c

Avoiding feed_handler to crash and stop feed_updater service

lib/feed_handler.rb
... ... @@ -65,7 +65,12 @@ class FeedHandler
65 65 if container.update_errors > FeedHandler.max_errors
66 66 container.enabled = false
67 67 end
68   - container.finish_fetch
  68 + begin
  69 + container.finish_fetch
  70 + rescue Exception => finish_fetch_exception
  71 + RAILS_DEFAULT_LOGGER.warn("Unable to finish fetch from %s ID %d\n%s" % [container.class.name, container.id, finish_fetch_exception.to_s])
  72 + RAILS_DEFAULT_LOGGER.warn("Backtrace:\n%s" % finish_fetch_exception.backtrace.join("\n"))
  73 + end
69 74 end
70 75 end
71 76  
... ...
test/unit/feed_handler_test.rb
... ... @@ -114,4 +114,11 @@ class FeedHandlerTest < Test::Unit::TestCase
114 114 end
115 115 end
116 116  
  117 + should 'not crash even when finish fetch fails' do
  118 + container.stubs(:finish_fetch).raises(Exception.new("crash"))
  119 + assert_nothing_raised do
  120 + handler.process(container)
  121 + end
  122 + end
  123 +
117 124 end
... ...