Sha256: a6c01cb42857377d5273bf0dccc04d265c1709a2730a903cef06ea9e7ed2c73f

Contents?: true

Size: 642 Bytes

Versions: 6

Compression:

Stored size: 642 Bytes

Contents

# this worker would test thread issues that were discussed before
require "net/http"
class RssWorker < BackgrounDRb::MetaWorker
  set_worker_name :rss_worker
  def create(args = nil)
    # this method is called, when worker is loaded for the first time
  end

  # method would fetch supplied urls in a thread
  def fetch_url(url)
    puts "fetching url #{url}"
    thread_pool.defer(:scrap_things,url)
  end

  def scrap_things url
    begin
      data = Net::HTTP.get(url,"/")
      File.open("#{RAILS_ROOT}/log/pages.txt","w") do |fl|
        fl.puts(data)
      end
    rescue
      logger.info "Error downloading page"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
backgroundrb-rails3-1.1.6 examples/workers/rss_worker.rb
backgroundrb-rails3-1.1.5 examples/workers/rss_worker.rb
backgroundrb-rails3-1.1.3 examples/workers/rss_worker.rb
backgroundrb-rails3-1.1.2 examples/workers/rss_worker.rb
backgroundrb-rails3-1.1.1 examples/workers/rss_worker.rb
backgroundrb-rails3-1.1 examples/workers/rss_worker.rb