Just a quick question. After watching RailsCasts ep #168 and coming across the following code:
class FeedEntry < ActiveRecord::Base
def self.update_from_feed(feed_url)
feed = Feedzirra::Feed.fetch_and_parse(feed_url)
add_entries(feed.entries)
end
def self.update_from_feed_continuously(feed_url, delay_interval = 15.minutes)
feed = Feedzirra::Feed.fetch_and_parse(feed_url)
add_entries(feed.entries)
loop do
sleep delay_interval
feed = Feedzirra::Feed.update(feed)
add_entries(feed.new_entries) if feed.updated?
end
end
private
def self.add_entries(entries)
entries.each do |entry|
unless exists? :guid => entry.id
create!(
:name => entry.title,
:summary => entry.summary,
:url => entry.url,
:published_at => entry.published,
:guid => entry.id
)
end
end
end
end
I'm asking myself where/when should I call the method self.update_from_feed_continuously(blah, blah)? Is it going to be in my Feed Controller, or a View (ie Index, show, etc..)
Any help is much appreciated. This question has been bugging me for a while...
It is just a method to fetch feeds from the input url continuously.
It can be called at anywhere, it depended on the situation.
When you submit the feed url through controller
, then call the method in controller
.
When you decide that the feed task should be run regularly, then it can be called by a rake
task through whenever
, https://github.com/javan/whenever