Skip to content

Instantly share code, notes, and snippets.

@pauldix
Created May 29, 2012 21:00
Show Gist options
  • Save pauldix/2830675 to your computer and use it in GitHub Desktop.
Save pauldix/2830675 to your computer and use it in GitHub Desktop.
ideas for fetching
# set the thread pool size and the timeout in seconds.
fetcher = Feedzirra::Fetcher.new({:thread_pool_size => 100, :timeout => 5})
# some feed data objects. also include feed_entry data objects
feeds = [Feed.new({:entries => [], etag => "..", :last_modified => "...", :url => "...", :feed_url => "...", :title => ""})]
# async style
fetcher.get(feeds, :on_success => lambda {|feed, updated_feed| ...}, :on_failure => lambda {|feed, failure_object| ...})
# that returns before finishing fetching the feeds. just adds them to a thread-safe queue to be processed by a worker pool.
# the failure condition could actually call fetcher.get on the failed feed again if you wanted to retry.
fetcher.join # wait until everything has completed. like thread.join
# sync style. will still get multi-threaded, but won't return until every feed has processed
results = fetcher.get(feeds)
# where results is a hash with the feed as the key and the result (either updated feed or failure object) as the value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment