Commit 8c98210cd2f19c8889304c949c46a74a88f1833d
1 parent
95d5df36
Exists in
master
and in
14 other branches
FeedHandler: extract methods
Let's isolate those bits of logic under meaningful names to make the code easier to understand.
Showing
1 changed file
with
9 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 < (Time.now - FeedHandler.disabled_period) | |
112 | + end | |
113 | + | |
106 | 114 | end | ... | ... |