root/trunk/examples/workers/rss_worker.rb

Revision 327, 0.6 kB (checked in by gethema..@gmail.com, 5 months ago)

sync code with git

Line 
1 # this worker would test thread issues that were discussed before
2 require "net/http"
3 class RssWorker < BackgrounDRb::MetaWorker
4   set_worker_name :rss_worker
5   def create(args = nil)
6     # this method is called, when worker is loaded for the first time
7   end
8
9   # method would fetch supplied urls in a thread
10   def fetch_url(url)
11     puts "fetching url #{url}"
12     thread_pool.defer(:scrap_things,url)
13   end
14
15   def scrap_things url
16     begin
17       data = Net::HTTP.get(url,"/")
18       File.open("#{RAILS_ROOT}/log/pages.txt","w") do |fl|
19         fl.puts(data)
20       end
21     rescue
22       logger.info "Error downloading page"
23     end
24   end
25 end
26
Note: See TracBrowser for help on using the browser.