Note that there are some explanatory texts on larger screens.

plurals
  1. POShould I be using EM::Synchrony::Multi or EM::Synchrony::FiberIterator with Goliath?
    primarykey
    data
    text
    <p>Maybe this is the wrong approach, but I'm <a href="https://github.com/postrank-labs/goliath/wiki/Asynchronous-Processing" rel="nofollow">trying to parallelize</a> <a href="https://github.com/igrigorik/em-synchrony/blob/master/lib/em-synchrony/em-hiredis.rb" rel="nofollow">em-hiredis</a> puts and lookups in Goliath with <code>EM::Synchrony::Multi</code> or <code>EM::Synchrony::FiberIterator</code>. However, I can't seem to access basic values <a href="https://github.com/postrank-labs/goliath/wiki/Configuration" rel="nofollow">initialized in the config</a>. I keep getting <code>method_missing</code> errors.</p> <p>Here's the basic watered down version of what I'm trying to do:</p> <pre><code>/lib/config/try.rb config['redisUri'] = 'redis://localhost:6379/0' config['redis_db'] ||= EM::Hiredis.connect config['user_agent'] = "MyCrawler Mozilla/5.0 Compat etc." </code></pre> <p>Here's the basic Goliath Setup</p> <pre><code>/try.rb require "goliath" require "em-hiredis" require "em-synchrony/fiber_iterator" require "em-synchrony/em-hiredis" require "em-synchrony/em-multi" class Try &lt; Goliath::API use Goliath::Rack::Params use Goliath::Rack::DefaultMimeType def response(env) case env['REQUEST_PATH'] when "/start" then start_crawl() body = "STARTING" [200, {}, body] end end def start_crawl urls = ["http://www.example.com/", "http://www.example.com/photos/", "http://www.example.com/video/", ] EM::Synchrony::FiberIterator.new(urls, 3).each do |url| p "#{user_agent}" redis_db.sadd 'test_queue', url end # multi = EM::Synchrony::Multi.new # urls.each_with_index do |url, index| # p "#{user_agent}" # multi.add index, redis_db.sadd('test_queue', url) # end end end </code></pre> <p>However, I keep getting errors where Goliath doesn't know what <code>user_agent</code> is or <code>redis_db</code> which were initialized in the config.</p> <pre><code>[936:INFO] 2012-09-21 23:47:10 :: Starting server on 0.0.0.0:9000 in development mode. Watch out for stones. /Users/ewu/.rvm/gems/ruby-1.9.3-p194@crawler/gems/goliath-1.0.0/lib/goliath/api.rb:143:in `method_missing': undefined local variable or method `user_agent' for #&lt;Try:0x007ff5a431c4e0 @opts={}&gt; (NameError) from ./lib/try.rb:27:in `block in start_crawl' from /Users/ewu/.rvm/gems/ruby-1.9.3-p194@crawler/gems/em-synchrony-1.0.2/lib/em-synchrony/fiber_iterator.rb:10:in `call' from /Users/ewu/.rvm/gems/ruby-1.9.3-p194@crawler/gems/em-synchrony-1.0.2/lib/em-synchrony/fiber_iterator.rb:10:in `block (2 levels) in each' ... ... ... </code></pre> <p>Ideally I'd be able to get <code>FiberIterator</code> working, because I have additional conditionals to check for:</p> <pre><code>EM::Synchrony::FiberIterator.new(urls, 3).each do |new_url} is_member = redis_db.sismember('crawled_urls', new_url) is_member += redis_db.sismember('queued_urls', new_url) if is_member == 0 redis_db.lpush 'crawl_queue', new_url redis_db.sadd 'queued_urls', new_url end end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload