Question

I have a worker which reads from a url and retrieves some data. So I'm using pool to achieve concurrency of 10 concurrent workers:

require 'nokogiri'
require 'open-uri'
require 'celluloid/autostart'

 class WebWorker
    include Celluloid
    def get_data
      url = "http://example.com/"
      doc = Nokogiri::HTML( open( url ), nil, "UTF-8" )
      { data: doc.css("body h1")[0].content.strip }
    end
  end

pool = WebWorker.pool(:size => 10)
10.times do |t|
   futures = 10.times.map{ |t| pool.future(:get_data) }
   results = futures.map(&:value)
end

Place the code above in a file named some_name.rb, run it, and you will get:

D, [2014-05-09T10:15:06.061071 #6588] DEBUG -- : Terminating 15 actors... W, [2014-05-09T10:15:06.063755 #6588] WARN -- : Terminating task: type=:finalizer, meta={:method_name=>:shutdown}, status=:callwait

My question is how do I suspend these messages? Wrapping in a begin..rescue doesn't help. And, why there are warnings appear, is anything wrong with the code?

Thanks!

Était-ce utile?

La solution

Needed to add:

# Use the logger of your Rails application.
Celluloid.logger = Rails.logger

Autres conseils

Terminate pool's links before program exit:

pool.links.each(&:terminate)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top