Changeset 280
- Timestamp:
- 12/16/07 04:16:04 (8 months ago)
- Files:
-
- trunk/README (modified) (2 diffs)
- trunk/script/bdrb_test_helper.rb (modified) (1 diff)
- trunk/server/meta_worker.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/README
r279 r280 332 332 333 333 334 * Using Threads inside BackgrounDRb 334 * Using Threads inside BackgrounDRb : 335 335 336 336 Remember BackgrounDRb follows event model of network programming, but sad truth of life is 337 337 not all networking libraries follow this model and hence they make use of blocking IO and threads. 338 B ut you need not fear, BackgrounDRb allows you to run all such tasks concurrently in threads338 BackgrounDRb allows you to run all such tasks concurrently in threads 339 339 which are internally managed by BackgrounDRb thread pool. 340 340 341 Each worker has access to object "thread_pool" which can be used to run task in threadsconcurrently.341 Each worker has access to object +thread_pool+ which can be used to run task in a thread concurrently. 342 342 343 343 thread_pool.defer(wiki_scrap_url) { |wiki_url| scrap_wikipedia(wiki_url) } 344 344 345 So whatever task you specify within scrap_wikipedia()is going to run concurrently.345 So whatever task you specify within +scrap_wikipedia+ is going to run concurrently. 346 346 347 347 WARNING: You shouldn't try to use +register_status+ method from within the block supplied to +defer+. Because, if you do that, … … 387 387 end 388 388 389 All above helper file does is that it stubs out, relevant worker methods, 390 which really need network IO. There can be methods added, which aren't 391 stubbed, for all such methods you are encouraged to stub them and send 392 the patch to the backgroundrb mailing list. 393 389 394 390 395 trunk/script/bdrb_test_helper.rb
r266 r280 1 require File. join(File.dirname(__FILE__) + "/../config/environment")1 require File.dirname(__FILE__) + '/../test_helper' 2 2 WORKER_ROOT = RAILS_ROOT + "/lib/workers" 3 3 $LOAD_PATH.unshift(WORKER_ROOT) trunk/server/meta_worker.rb
r279 r280 37 37 # can be used to make a call in threaded manner 38 38 # passed block runs in a thread from thread pool 39 # for example in a worker method you can do: 39 40 # def fetch_url(url) 40 41 # puts "fetching url #{url}" … … 52 53 # you can invoke above method from rails as: 53 54 # MiddleMan.ask_work(:worker => :rss_worker, :worker_method => :fetch_url, :data => "www.example.com") 55 # assuming method is defined in rss_worker 54 56 55 57 def defer(*args,&block)
