Created
December 30, 2008 14:13
-
-
Save gnufied/41629 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/usr/lib/ruby/1.8/timeout.rb:54:in `rbuf_fill': execution expired (Timeout::Error) | |
from /usr/lib/ruby/1.8/timeout.rb:56:in `timeout' | |
from /usr/lib/ruby/1.8/timeout.rb:76:in `timeout' | |
from /usr/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill' | |
from /usr/lib/ruby/1.8/net/protocol.rb:116:in `readuntil' | |
from /usr/lib/ruby/1.8/net/protocol.rb:126:in `readline' | |
from /usr/lib/ruby/1.8/net/http.rb:2029:in `read_status_line' | |
from /usr/lib/ruby/1.8/net/http.rb:2018:in `read_new' | |
from /usr/lib/ruby/1.8/net/http.rb:1059:in `request' | |
... 24 levels... | |
from /usr/lib/ruby/gems/1.8/gems/packet-0.1.13/bin/packet_worker_runner:47:in `new' | |
from /usr/lib/ruby/gems/1.8/gems/packet-0.1.13/bin/packet_worker_runner:47 | |
from /usr/bin/packet_worker_runner:19:in `load' | |
from /usr/bin/packet_worker_runner:19 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "feed-normalizer" | |
require 'open-uri' | |
class FetcherWorker < BackgrounDRb::MetaWorker | |
set_worker_name :fetcher_worker | |
def create(args = nil) | |
fetch_new_items_for_all_linkblogs | |
end | |
def fetch_new_items_for_all_linkblogs | |
logger.info "[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] Checking for new items in all link blogs" | |
@linkblogs = Linkblog.all | |
@linkblogs.each do |lb| | |
begin | |
fetch_new_items(lb.id) | |
rescue Timeout::Error => e | |
logger.info("Timeout error while fetching docs") | |
rescue | |
logger.info("Something else") | |
end | |
end | |
end | |
def fetch_new_items(linkblog_id) | |
@lb = Linkblog.find(linkblog_id) | |
unless @lb.nil? | |
logger.info "[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] Processing #{@lb.feed_url}" | |
# http://github.com/aasmith/feed-normalizer/tree/master | |
feed = FeedNormalizer::FeedNormalizer.parse open(@lb.feed_url) | |
unless feed.nil? | |
feed.entries.each do |item| | |
begin | |
unless @lb.posts.find_by_post_url(item.url) | |
@post = @lb.posts.create(:title => item.title, | |
:post_url => item.url, | |
:processed => false, | |
:content => item.content || item.description) | |
logger.info "[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] creating post: #{item.title}" | |
@post.publish_date = DateTime.parse(item.date_published.to_s) if item.date_published | |
@post.save! | |
MiddleMan.worker(:parser_worker).parse_post(:arg => @post.id, :job_key => "post_#{@post.id}") | |
end | |
rescue Exception => e | |
logger.error e | |
logger.info "Item url: #{item.url}" | |
logger.info "Date published: #{item.date_published}" | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment