Class: Infosource
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Infosource
- Includes:
- InfosourcesHelper
- Defined in:
- app/models/infosource.rb
Constant Summary collapse
- MIN_SOURCENAME_SIZE =
3
- MAX_SOURCENAME_SIZE =
40
- RANGE_SOURCENAMESIZE =
(3..40)
Class Method Summary collapse
-
.fetch_all_sources ⇒ Object
TODO updating feed using the Feedzirra, the feeds should be mapped to the articles model.
Instance Method Summary collapse
Class Method Details
.fetch_all_sources ⇒ Object
TODO updating feed using the Feedzirra, the feeds should be mapped to the articles model
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/infosource.rb', line 43 def self.fetch_all_sources Rails.logger.info "Starting to fetch feeds for #{Infosource.count} infosources." begin total_fetches = 0 Infosource.all.each do |infosource| total_fetches += infosource.fetch_source || 0 end rescue Exception #TODO test for failed fetching Rails.logger.error("Error occured during fetching all infosources: #{$!}") ensure Sunspot.commit_if_dirty Rails.logger.info "#{total_fetches} articles were fetched. Harvesting finished." end total_fetches end |
Instance Method Details
#fetch_source ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/infosource.rb', line 20 def fetch_source if has_sourcefeed? begin #TODO simulate Feedzirra collapse in tests feed = Feedzirra::Feed.fetch_and_parse(self.sourcefeed) rescue Exception Rails.logger.error("Error occured during fetching infosource #{self.sourcename} (#{self.sourcefeed}): #{$!}") end if feed != 0 entries_count = add_entries(feed.entries) Rails.logger.info "Infosource #{self.sourcename}'s fetched from feed #{self.sourcefeed}, #{entries_count} entries added." else entries_count = nil Rails.logger.error "Infosource #{self.sourcename} count not be fetched. An error occured." end else entries_count = nil Rails.logger.info "Infosource #{self.sourcename} has not feed set, nothing fetched." end entries_count end |